title: Laravel error: Creating default object from empty value
body: <p>I'm trying to update a record in the database . I'm trying to update an already registered product, then I do the research and then create several objects to save , the problem that laravel returns an error mesage warning that I am trying to create an object with a null value , and I'm passing a value for he. Follows the code below</p>
  
  <p><a href="https://i.stack.imgur.com/989hK.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/989hK.png" alt="enter image description here"></a></p>
  
  <p>Model</p>
  
  <p><a href="https://i.stack.imgur.com/zrxy4.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/zrxy4.png" alt="enter image description here"></a></p>
  
  <p><a href="https://i.stack.imgur.com/z9H50.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/z9H50.png" alt="I can&#39;t resolve this error, i need some help!!!"></a></p>
  
  <pre><code>public function edit()
  {
      $idProduct = Input::get('pid');
  
      $produto = ProductModel::where('id', $idProduct)-&gt;first();
  
      $nome = Input::get('eNome');
      $descricao = Input::get('eDescricao');
      $userID = Auth::user()-&gt;id;
  
      $produto-&gt;nome = $nome;
      $produto-&gt;descricao = $descricao;
      $produto-&gt;users_id = $userID;
  
      if (Input::hasFile('eFoto'))
      {
          $file = Input::file('eFoto');
  
          $fileNameUniq = uniqid();
          $destinationPath = public_path().'assets/admin/gallery/';
  
  
          $extension = pathinfo($file-&gt;getClientOriginalName(), PATHINFO_EXTENSION);
  
          $fileName = uniqid();
          if(move_uploaded_file($file, 'assets/admin/gallery/'.$fileName.'.'.$extension)){
              $produto-&gt;foto = $fileName.'.'.$extension;
          }
  
      }
  
      $produto-&gt;save();
  
      return Redirect::back()-&gt;with(['message' =&gt; 'Produto alterado com sucesso!']);
  }
  </code></pre>
  
  <p>Routes:</p>
  
  <pre><code>Route::resource('/produto','admin\ProductController@index',['only' =&gt; 'index']);
  Route::get('/produto/editar/ativar','admin\ProductController@activeProduct',['only' =&gt; 'activeProduct']);
  Route::get('/produto/editar/desativar','admin\ProductController@disableProduct',['only' =&gt; 'disableProduct']);
  Route::get('/produto/editar/{id}', array('as' =&gt; 'editProduct', 'uses' =&gt; 'Admin\ProductController@editProduct'));
  Route::get('/produto/excluir','admin\ProductController@destroy',['only' =&gt; 'destroy']);
  Route::any('/produto/add','admin\ProductController@store',['only' =&gt; 'store']);
  Route::post('/produto/editar','admin\ProductController@edit',['only' =&gt; 'edit']);
  </code></pre>
  
  <p>View</p>
  
  <pre><code>&lt;div class="modal"&gt;
                &lt;div class="modal-dialog"&gt;
                  &lt;div class="modal-content"&gt;
                    &lt;div class="modal-header"&gt;
                      &lt;button type="button" class="close" data-dismiss="modal" aria-label="Close"&gt;&lt;span aria-hidden="true"&gt;&amp;times;&lt;/span&gt;&lt;/button&gt;
                      &lt;h4 class="modal-title"&gt;Editar produto&lt;/h4&gt;
                    &lt;/div&gt;
                    &lt;div class="modal-body"&gt;
                      &lt;link href="http://fonts.googleapis.com/css?family=PT+Sans+Narrow:400,700" rel='stylesheet' /&gt;
  
                      &lt;!-- The main CSS file --&gt;
                      &lt;link href="{{URL::asset('/')}}assets/admin/uploader/css/style.css" rel="stylesheet" /&gt;
                      &lt;!--&lt;form id="upload" method="post" action="app\controllers\admin\GalleryController@store" enctype="multipart/form-data"&gt;--&gt;
  
                      {!! Form::open(['id' =&gt; 'product', 'method' =&gt; 'POST', 'enctype' =&gt; 'multipart/form-data', 'files' =&gt; true, 'action' =&gt; 'admin\ProductController@edit']) !!}
                          &lt;div class="clearfix"&gt;
                              {!! Form::text('eNome', $eProduct-&gt;nome,['class' =&gt; 'form-control', 'required' =&gt; 'required']) !!}
                          &lt;/div&gt;
                          &lt;br&gt;
                          &lt;div class="row"&gt;
                              &lt;div class="form-group foto col-xs-12"&gt;
                                  &lt;label&gt;Foto atual: &lt;a href="{{URL::asset('/')}}assets/admin/gallery/{{$eProduct-&gt;foto}}"&gt;&lt;img src="{{URL::asset('/')}}assets/admin/gallery/{{$product-&gt;foto}}" width="100%" height="300px" class="user-image" alt="Imagem"/&gt;&lt;/a&gt;&lt;/label&gt;
                                  &lt;br&gt;
                                  &lt;label&gt;Selecione uma nova foto:&lt;/label&gt;
                                  &lt;input class="form-control" type="file" name="eFoto" value="" /&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;br&gt;
                          &lt;div class="clearfix"&gt;
                              {!! Form::textarea('eDescricao', $eProduct-&gt;descricao,['class' =&gt; 'form-control', 'placeholder' =&gt; 'descricao', 'required' =&gt; 'required']) !!}
                          &lt;/div&gt;
                          &lt;br&gt;
  
                     {!! Form::close() !!}
                    &lt;/div&gt;
                    &lt;div class="modal-footer"&gt;
                      &lt;!--&lt;button type="button" class="btn btn-default pull-left" data-dismiss="modal"&gt;Fechar&lt;/button&gt;--&gt;
                       &lt;a class="btn btn-success pull-left"  href="{{URL::to('/yziadmin/produto')}}"&gt;Fechar&lt;/a&gt;
                      {!! Form::hidden('pid', $eProduct-&gt;id) !!}
                      {!! Form::submit('Salvar', ['name'=&gt;'btnsave', 'class'=&gt;'btn btn-success pull-right', 'form'=&gt;'product']) !!}
                      &lt;!--&lt;button type="button" class="btn btn-primary"&gt;Finalizar&lt;/button&gt;--&gt;
                    &lt;/div&gt;
                  &lt;/div&gt;&lt;!-- /.modal-content --&gt;
                &lt;/div&gt;&lt;!-- /.modal-dialog --&gt;
              &lt;/div&gt;&lt;!-- /.modal --&gt;
  </code></pre>