Framework: Creating default object from empty value Laravel 5.6

Created on 6 Jun 2018  路  1Comment  路  Source: laravel/framework

  • Laravel Version: 5.6
  • PHP Version: 7.1 +
  • Database Driver & Version: mySQL

Description:
I'm trying to Edit details of User, Edit working Fine but not for Multiple Images, Single Image Being Edit not Multiple images, Got the error see image of error also my controller code am i missing something ?

========= Controller Started ===============

public function update(Request $request, $id)
{
$mainPhoto = $request->file('mainPhoto');
$otherPhotos = $request->file('otherPhotos');
$fashionPhotos = $request->file('fashionPhotos');
$arabicPhotos = $request->file('arabicPhotos');
$model = OurModels::find($id);

    $slug = str_slug($request->name);

    // Main Photo Code Start 

    if(isset($mainPhoto))
    {
      $currentDate = Carbon::now()->toDateString();
      $mainPhotoName = $slug .'-'. $currentDate .'-'. uniqid() .'.'. $mainPhoto->getClientOriginalExtension();

      if(!file_exists('uploads/models/mainPhoto'))
      {
        mkdir('uploads/models/mainPhoto', 0777, true);
      }

      if(file_exists('uploads/models/mainPhoto/'.$model->mainPhoto))
      {
        unlink('uploads/models/mainPhoto/'.$model->mainPhoto);
      }

      $mainPhoto->move('uploads/models/mainPhoto', $mainPhotoName);
    }else{
      $mainPhotoName = $model->mainPhoto;
    }

      // Main Photo Code End

      $model->name = $request->name;
      $model->dateofBirth = $request->dateob;
      $model->age = $request->age;
      $model->height = $request->height;
      $model->chest = $request->chest;
      $model->waist = $request->waist;
      $model->hips = $request->hips;
      $model->eye = $request->eye;
      $model->skin = $request->skin;
      $model->shoes = $request->shoes;
      $model->gender = $request->gender;
      $model->haircolor = $request->haircolor;
      $model->mobileNumber = $request->mobileNumber;
      $model->email = $request->email;
      $model->category = $request->category;
      $model->mainPhoto = $mainPhotoName;
      $model->save();
      $model->ethnicities()->sync($request->ethnicities);


      // Other Photos Code Start
      if(isset($otherPhotos)) {

        if(!file_exists('uploads/models/otherPhotos')) {
          mkdir('uploads/models/otherPhotos', 0777, true);
        }

        foreach($otherPhotos as $otherPhoto) { 
          $currentDate = Carbon::now()->toDateString();
          $otherPhotoName = $slug.'-'.$currentDate.'-'.uniqid().'.'.$otherPhoto->getClientOriginalExtension();
          Image::make($otherPhoto)->save('uploads/models/otherPhotos/'.$otherPhotoName,50);
          $otherPhoto = OtherPhoto::find($id);
          $otherPhoto->our_models_id = $model->id;
          $otherPhoto->image = $otherPhotoName;
          $otherPhoto->save();
        }

        if(file_exists('uploads/models/otherPhotos/'.$otherPhoto->image))
        {
          unlink('uploads/models/otherPhotos/'.$otherPhoto->image);
        }   

      }else{
             $otherPhotoName = $otherPhotos;   
      }

    // Other Photos Code End

    // Fashion k Code Start
      if(isset($fashionPhotos)) {

        if(!is_dir('uploads/models/fashionPhotos')) {
          mkdir('uploads/models/fashionPhotos', 0777, true);
        }


        foreach($fashionPhotos as $fashionPhoto) {  
          $currentDate = Carbon::now()->toDateString();
          $fashionPhotoName = $slug.'-'.$currentDate.'-'.uniqid().'.'.$fashionPhoto->getClientOriginalExtension();
          Image::make($fashionPhoto)->save('uploads/models/fashionPhotos/'.$fashionPhotoName,50);
          $fashionPhoto = FashionPhoto::find($id);
          $fashionPhoto->our_models_id = $model->id;
          $fashionPhoto->image = $fashionPhotoName;
          $fashionPhoto->save();
        }

        if(file_exists('uploads/models/fashionPhotos/'.$fashionPhoto->image))
        {
          unlink('uploads/models/fashionPhotos/'.$fashionPhoto->image);
        }

      }else{
             $fashionPhotoName = $fashionPhotos;   
      }

    // Fashion Photos Code End

    // Arabic Photos Code Start
      if(isset($arabicPhotos)) {

        if(!file_exists('uploads/models/arabicPhotos')) {
          mkdir('uploads/models/arabicPhotos', 0777, true);
        }

        foreach($arabicPhotos as $arabicPhoto) {
          $currentDate = Carbon::now()->toDateString();
          $arabicPhotoName = $slug.'-'.$currentDate.'-'.uniqid().'.'.$arabicPhoto->getClientOriginalExtension();
          Image::make($arabicPhoto)->save('uploads/models/arabicPhotos/'.$arabicPhotoName,50);
          $arabicPhoto = ArabicPhoto::find($id);
          $arabicPhoto->our_models_id = $model->id;
          $arabicPhoto->image = $arabicPhotoName;
          $arabicPhoto->save();
        }

        if(file_exists('uploads/models/arabicPhotos/'.$arabicPhoto->image))
        {
          unlink('uploads/models/arabicPhotos/'.$arabicPhoto->image);
        }

      }else{
             $arabicPhotoName = $arabicPhotos;   
      }

    // Arabic Photos Code End    

    return redirect()->route('ourmodels.index')->with('successMsg', 'Model Updated !');
}

========= Controller End ===================

Most helpful comment

Do we really need to read those 140-150 lines of code, or can you provide a smaller code snippet to reproduce the problem? Are you trying to report a bug in the framework, or start a discussion? This repository is for bugs, if you want to chat you should try in the forums or on Slack.

>All comments

Do we really need to read those 140-150 lines of code, or can you provide a smaller code snippet to reproduce the problem? Are you trying to report a bug in the framework, or start a discussion? This repository is for bugs, if you want to chat you should try in the forums or on Slack.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

progmars picture progmars  路  3Comments

felixsanz picture felixsanz  路  3Comments

kerbylav picture kerbylav  路  3Comments

PhiloNL picture PhiloNL  路  3Comments

YannPl picture YannPl  路  3Comments