getClientOriginalName на null с присутствующими данными и без перезаписанных функций, которые будут переименовывать файлы

Полная ошибка

2020-04-09 15:04:47] local.ERROR: Вызов функции-члена getClientOriginalName() при нулевом значении {"исключение":"[объект] (Symfony\Component\Debug\Exception\FatalThrowableError(code: 0): Вызов функции-члена getClientOriginalName() с нулевым значением в C:app\Http\Controllers\ContactsController.php:111)

Нет ничего очевидного в синтаксической ошибке или просто в том, что код, который мне нужен, находится в нужных местах. Метод getClientOriginalName работает. Я просто не вижу свои отправленные файлы в базе данных PHPAdmin. Я работаю в среде Laravel. Кажется, не могу понять, почему файл не отправляется

PHP

  public function processCsv(Request $request)
    {   
        $file = $request->file('file');
        $showOrganizationFields = $request->show_organization_fields;
        //Laravel way to store a local request temporarily in the browser 
        $result = Storage::disk('local')->putFileAs('tempcsv',  $file, $file->getClientOriginalName());
        $rows = SimpleExcelReader::create(storage_path('app/' . $result))->getRows();
        dd($request->file('file')->getClientOriginalName());



        try
        {
            $rows->each (function(array $rowProperties) 

            {
                $account = new Account();
                $userSelection = $request->$userSelection;
                $account->name = $rowProperties[$userSelection['account_name']];

                //One-To-Many Eloquent Relationship that links a table of Account Names in the Account's 
                //table to contact Account_ID's in the Contact tables  
                //$contact->id = $account->id;



                $account->save();


                $contact = new Contact();
                $contact->id = $account->id;
                $contact->contact_id = $rowProperties[$userSelection['contact_account_name']];
                $contact->first_name = $rowProperties[$userSelection['contact_first_name']];
                $contact->last_name = $rowProperties[$userSelection['contact_last_name']];






                if(isset($userSelection['contact_email']))
                {
                    $contact->email = $rowProperties[$userSelection['contact_email']];
                }
                if(isset($userSelection['contact_phone']))
                {
                    $contact->phone = $rowProperties[$userSelection['contact_phone']];
                }
                if(isset($userSelection['contact_address']))
                {
                    $contact->address = $rowProperties[$userSelection['contact_address']];
                }
                if(isset($userSelection['contact_address']))
                {
                    $contact->address = $rowProperties[$userSelection['contact_address']];
                }
                if(isset($userSelection['contact_city']))
                {
                    $contact->city = $rowProperties[$userSelection['contact_city']];
                }
                if(isset($userSelection['contact_region']))
                {
                    $contact->region = $rowProperties[$userSelection['contact_region']];
                }
                if(isset($userSelection['contact_updated_at']))
                {
                    $contact->updated_at = $rowProperties[$userSelection['contact_updated_at']];
                }
                if(isset($userSelection['contact_created_at']))
                {
                    $contact->created_at = $rowProperties[$userSelection['contact_created_at']];
                }
                if(isset($userSelection['contact_deleted_at']))
                {
                    $contact->deleted_at = $rowProperties[$userSelection['contact_deleted_at']];
                }

                if($request->$showOrganizationFields) 
                {


                $organization = new Organization();
                $organization->first_name = $rowProperties[$userSelection['organziation_first_name']];
                $organization->last_name = $rowProperties[$userSelection['organization_last_name']];



                if(isset($userSelection['organization_name']))
                {
                    $orgnization->name = $rowProperties[$userSelection['organization_name']];
                }
                if(isset($userSelection['organization_email']))
                {
                    $organization->email = $rowProperties[$userSelection['organization_email']];
                }
                if(isset($userSelection['organization_phone']))
                {
                    $organization->phone = $rowProperties[$userSelection['organization_phone']];
                }
                if(isset($userSelection['organization_address']))
                {
                    $organization->address = $rowProperties[$userSelection['organization_address']];
                }
                if(isset($userSelection['organization_city']))
                {
                    $organization->city = $rowProperties[$userSelection['organization_city']];
                }
                if(isset($userSelection['organization_region']))
                {
                    $organization->region = $rowProperties[$userSelection['organization_region']];
                }
                if(isset($userSelection['organization_updated_at']))
                {
                    $organization->updated_at = $rowProperties[$userSelection['organization_updated_at']];
                }
                if(isset($userSelection['organization_deleted_at']))
                {
                    $organization->deleted_at = $rowProperties[$userSelection['organization_deleted_at']];
                }

                }

            });
        } 
        catch(Exception $exception)

        {
               return response()->json(['error' => 'exception on error', 'message'=>$exception->getMessage()]);
        }




    }

HTML

<form enctype="multipart/form-data" action="" method="post" id="csvFile" ref="csvFile" >
  <div>
    <div class="large-12 medium-12 small-12 cell">
    <input type="file" id="file" ref="file" @change="handleFileUpload()"/>
  </div>

Vue.js

submitFiles() 
    {
      //Form validation that will not allow a user to submit the form by upon the @click "Submit" event 
      if(!this.$refs.csvFile.checkValidity())
      {
        return null;
      }
      let formData = new FormData();
      formData.append('file', this.file);
      formData.append('show_organization_fields', this.showOrganizationFields);
      axios.post('http://localhost:8080/api/contacts/process-csv',
      {
      headers: 
        {
          'Content-Type': 'multipart/form-data'
        }
      }
      )
      .then(function(response){
        console.log('SUCCESS!!');
        console.log(response);

      })
      .catch(function(response){
        console.log('FAILURE!!');
        console.log(response);

      })
    }

0 ответов

Другие вопросы по тегам