title: ErrorException in ClientController.php line 120: Attempt to assign property of non-object Laravel 5.2
body: <p>I am completing a form to edit clients, it must attach an image using intervention image and it is generating the following error:</p>
  
  <blockquote>
    <p>ErrorException in ClientController.php line 120: Attempt to assign
    property of non-object.</p>
  </blockquote>
  
  <p>This is my model:</p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Database\Eloquent\Model;
  
  class Client extends Model
  {
      protected $table = 'clients';
  
      protected $fillable = ['status_id', 'name', 'identity', 'address', 'location', 'l_number', 'province_id', 'email', 'email2', 'phone', 'movil', 'requirement_id', 'budget', 'user_id', 'comments'];
  
      // Relation with Status client
      public function statusclient()
      {
          return $this-&gt;belongsTo('App\Statusclient', 'status_id');
      }
  
      // Relation with Province
      public function province()
      {
          return $this-&gt;belongsTo('App\Province');
      }
  
      // Relation with Province
      public function requirement()
      {
          return $this-&gt;belongsTo('App\Requirement');
      }
  
      // Relation with User
      public function user()
      {
          return $this-&gt;belongsTo('App\User');
      }
  }
  </code></pre>
  
  <p>This is my update method:</p>
  
  <pre><code>public function update(Request $request, $id)
      {
          $updated = Client::findorFail($id);
  
          $this-&gt;validate($request, [
              'name' =&gt; 'required'
          ]);
  
          $clients = $request-&gt;all();
  
          $updated-&gt;fill($clients)-&gt;save();
  
          if($request-&gt;hasFile('avatar')){
              $avatar = $request-&gt;file('avatar');
              $filename = time() . '.' . $avatar-&gt;getClientOriginalExtension();
              Image::make($avatar)-&gt;resize(300, 200)-&gt;save( public_path('uploads/clients/' . $filename ) );
  
              $clients-&gt;avatar = $filename;
              $clients-&gt;save();
          }   
  
          return redirect()-&gt;route('clients.index')
                          -&gt;with('success','Cliente actualizado satisfactoriamente!!!');
      }
  </code></pre>
  
  <p>This is the form:</p>
  
  <pre><code>{!! Form::model($clients, ['method' =&gt; 'PATCH','route' =&gt; ['clients.update', $clients-&gt;id], 'enctype' =&gt; 'multipart/form-data']) !!}
  
      &lt;div class="row"&gt;
  
          &lt;div class="col-md-4 col-xs-4"&gt; 
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Estado cliente:&lt;/strong&gt;
                  {!! Form::select('status_id', $statusclients, null, ['class' =&gt; 'form-control']) !!}
              &lt;/div&gt;  
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Nombre:&lt;/strong&gt;
                  {!! Form::text('name', null, array('placeholder' =&gt; 'Nombres o razón social','class' =&gt; 'form-control')) !!}
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Documento de identidad:&lt;/strong&gt;
                  {!! Form::text('identity', null, array('placeholder' =&gt; 'Cedula, pasaporte o RNC...','class' =&gt; 'form-control')) !!}
              &lt;/div&gt;
  
              &lt;!-- left column --&gt;
              &lt;div class="form-group"&gt;
                  &lt;div class="text-center"&gt;
                      &lt;a href="#" class="thumbnail"&gt;
                          &lt;img src="{{ URL::asset('uploads/clients/' . $clients-&gt;avatar) }}" class="avatar img-thumbnail" alt="avatar" style="height: 180px; width: 100%;"&gt;
                          &lt;h6&gt;Cambia la imagen del documento de identidad del cliente...&lt;/h6&gt;
                          &lt;input type="file" name="avatar" class="text-center center-block well well-sm" style="width: 100%;"&gt;
                      &lt;/a&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
  
          &lt;/div&gt;
  
          &lt;div class="col-md-4 col-xs-4"&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Dirección:&lt;/strong&gt;
                  {!! Form::text('address', null, array('placeholder' =&gt; 'Dirección','class' =&gt; 'form-control')) !!}
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Sector:&lt;/strong&gt;
                  {!! Form::text('location', null, array('placeholder' =&gt; 'Localidad','class' =&gt; 'form-control')) !!}
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Número:&lt;/strong&gt;
                  {!! Form::text('l_number', null, array('placeholder' =&gt; 'Número propiedad','class' =&gt; 'form-control')) !!}
              &lt;/div&gt; 
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Provincia:&lt;/strong&gt;
                  {!! Form::select('province_id', $provinces, null, ['class' =&gt; 'form-control']) !!}
              &lt;/div&gt;  
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Email:&lt;/strong&gt;
                  {!! Form::text('email', null, array('placeholder' =&gt; 'Email','class' =&gt; 'form-control')) !!}
              &lt;/div&gt;             
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Email secundario:&lt;/strong&gt;
                  {!! Form::text('email2', null, array('placeholder' =&gt; 'Email secundario','class' =&gt; 'form-control')) !!}
              &lt;/div&gt; 
  
              &lt;div class="row"&gt;           
  
                  &lt;div class="col-md-6"&gt;
  
                      &lt;div class="form-group"&gt;
                          &lt;strong&gt;Teléfono:&lt;/strong&gt;
                          {!! Form::text('phone', null, array('placeholder' =&gt; 'Número de teléfono','class' =&gt; 'form-control')) !!}
                      &lt;/div&gt;
  
                  &lt;/div&gt;
  
                  &lt;div class="col-md-6"&gt;
  
                      &lt;div class="form-group"&gt;
                          &lt;strong&gt;Movil:&lt;/strong&gt;
                          {!! Form::text('movil', null, array('placeholder' =&gt; 'Número de movil','class' =&gt; 'form-control')) !!}
                      &lt;/div&gt;  
  
                  &lt;/div&gt;
  
              &lt;/div&gt;        
  
          &lt;/div&gt;
  
          &lt;div class="col-md-4 col-xs-4"&gt;            
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Necesidad del cliente:&lt;/strong&gt;
                  {!! Form::select('requirement_id', $requirements, null, ['class' =&gt; 'form-control']) !!}
              &lt;/div&gt;
  
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Presupuesto:&lt;/strong&gt;
                  {!! Form::text('budget', null, array('placeholder' =&gt; 'Presupuesto del cliente','class' =&gt; 'form-control')) !!}
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Gestor:&lt;/strong&gt;
                  {!! Form::select('user_id', $users, null, ['class' =&gt; 'form-control']) !!}
              &lt;/div&gt;
              &lt;div class="form-group"&gt;
                  &lt;strong&gt;Comentarios:&lt;/strong&gt;
                  {!! Form::textarea('comments', null, array('placeholder' =&gt; 'Comentar sobre algun detalle sobre el cliente','class' =&gt; 'form-control', 'size' =&gt; '30x5')) !!}
              &lt;/div&gt;
          &lt;/div&gt;
  
          &lt;div class="form-group col-md-4 col-xs-4"&gt;
              &lt;a class="btn btn-warning" href="{{ route('clients.index') }}" data-toggle="tooltip" rel="tooltip" data-placement="top" title="Retornar"&gt;
                  &lt;i class="material-icons"&gt;arrow_back&lt;/i&gt;
              &lt;/a&gt;
  
              &lt;button type="submit" class="btn btn-success" data-toggle="tooltip" rel="tooltip" data-placement="top" title="Actualizar"&gt;
                  &lt;i class="material-icons"&gt;cached&lt;/i&gt;
              &lt;/button&gt;              
          &lt;/div&gt;
      &lt;/div&gt;
      {!! Form::close() !!}
  </code></pre>
  
  <p>This is the stack of errors in the browser:</p>
  
  <pre><code>1.  in ClientController.php line 120
  2.  at HandleExceptions-&gt;handleError('2', 'Attempt to assign property of non-object', 'C:\xampp\htdocs\zizaco_entrust\app\Http\Controllers\ClientController.php', '120', array('request' =&gt; object(Request), 'id' =&gt; '2', 'updated' =&gt; object(Client), 'clients' =&gt; array('_method' =&gt; 'PATCH', '_token' =&gt; 'Be325FU0P1utedgMUR1uR91QXQXoHsYFrlCCrXDa', 'status_id' =&gt; '2', 'name' =&gt; 'Jenny Lopez', 'identity' =&gt; '00010076966', 'address' =&gt; 'Calle 3ra, Esq. 9, Tropical del Este, Las Americas', 'location' =&gt; 'Tropical del Este, Las Americas', 'l_number' =&gt; '20', 'province_id' =&gt; '31', 'email' =&gt; 'jennylopez@gmail.com', 'email2' =&gt; 'jennylopez@outlook.com', 'phone' =&gt; '8095678910', 'movil' =&gt; '8298662101', 'requirement_id' =&gt; '1', 'budget' =&gt; '10000', 'user_id' =&gt; '2', 'comments' =&gt; 'Interesado en apartamento de 2 habitaciones, en la zona colonial. ', 'avatar' =&gt; object(UploadedFile)), 'avatar' =&gt; object(UploadedFile), 'filename' =&gt; '1479867405.jpg')) in ClientController.php line 120
  3.  at ClientController-&gt;update(object(Request), '2')
  4.  at call_user_func_array(array(object(ClientController), 'update'), array(object(Request), 'clients' =&gt; '2')) in Controller.php line 80
  5.  at Controller-&gt;callAction('update', array(object(Request), 'clients' =&gt; '2')) in ControllerDispatcher.php line 146
  6.  at ControllerDispatcher-&gt;call(object(ClientController), object(Route), 'update') in ControllerDispatcher.php line 94
  7.  at ControllerDispatcher-&gt;Illuminate\Routing\{closure}(object(Request))
  8.  at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
  9.  at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request))
  10. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
  11. at Pipeline-&gt;then(object(Closure)) in ControllerDispatcher.php line 96
  12. at ControllerDispatcher-&gt;callWithinStack(object(ClientController), object(Route), object(Request), 'update') in ControllerDispatcher.php line 54
  13. at ControllerDispatcher-&gt;dispatch(object(Route), object(Request), 'App\Http\Controllers\ClientController', 'update') in Route.php line 174
  14. at Route-&gt;runController(object(Request)) in Route.php line 140
  15. at Route-&gt;run(object(Request)) in Router.php line 724
  16. at Router-&gt;Illuminate\Routing\{closure}(object(Request))
  17. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
  18. at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in Authenticate.php line 28
  19. at Authenticate-&gt;handle(object(Request), object(Closure))
  20. at call_user_func_array(array(object(Authenticate), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  21. at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  22. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  23. at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in VerifyCsrfToken.php line 29
  24. at VerifyCsrfToken-&gt;handle(object(Request), object(Closure))
  25. at call_user_func_array(array(object(VerifyCsrfToken), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  26. at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  27. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  28. at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
  29. at ShareErrorsFromSession-&gt;handle(object(Request), object(Closure))
  30. at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  31. at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  32. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  33. at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
  34. at StartSession-&gt;handle(object(Request), object(Closure))
  35. at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  36. at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  37. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  38. at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
  39. at AddQueuedCookiesToResponse-&gt;handle(object(Request), object(Closure))
  40. at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  41. at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  42. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  43. at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
  44. at EncryptCookies-&gt;handle(object(Request), object(Closure))
  45. at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  46. at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  47. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  48. at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request))
  49. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
  50. at Pipeline-&gt;then(object(Closure)) in Router.php line 726
  51. at Router-&gt;runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
  52. at Router-&gt;dispatchToRoute(object(Request)) in Router.php line 675
  53. at Router-&gt;dispatch(object(Request)) in Kernel.php line 246
  54. at Kernel-&gt;Illuminate\Foundation\Http\{closure}(object(Request))
  55. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
  56. at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in Debugbar.php line 51
  57. at Debugbar-&gt;handle(object(Request), object(Closure))
  58. at call_user_func_array(array(object(Debugbar), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  59. at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  60. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  61. at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
  62. at CheckForMaintenanceMode-&gt;handle(object(Request), object(Closure))
  63. at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
  64. at Pipeline-&gt;Illuminate\Pipeline\{closure}(object(Request))
  65. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
  66. at Pipeline-&gt;Illuminate\Routing\{closure}(object(Request))
  67. at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
  68. at Pipeline-&gt;then(object(Closure)) in Kernel.php line 132
  69. at Kernel-&gt;sendRequestThroughRouter(object(Request)) in Kernel.php line 99
  70. at Kernel-&gt;handle(object(Request)) in index.php line 54
  </code></pre>