title: Edit and Updating Data in Laravel
body: <p>I am having some trouble editing data in Laravel. Here's the button to show Edit view: </p>
  
  <pre class="lang-html prettyprint-override"><code>{{ Form::open(array('route' =&gt; array('edit_spk', 'id'=&gt; $spk_data-&gt;id), 'method' =&gt; 'GET', 'style' =&gt; 'display:inline')) }}
  &lt;button class="btn btn-success btn-line btn-rect"&gt;
    &lt;i class="icon-pencil icon-white"&gt;&lt;/i&gt; Edit
  &lt;/button&gt;
  {{Form::close()}}                        
  </code></pre>
  
  <p>Here's the route: </p>
  
  
  
  <pre><code>Route::get('spk/edit/{id}', array('as'=&gt;'edit_spk','uses'=&gt;'SpkController@edit'));
  Route::put('spk/update/{id}', array('as'=&gt;'update_spk','uses'=&gt;'SpkController@update'));
  </code></pre>
  
  <p>Here's the controller:</p>
  
  
  
  <pre><code>public function edit($id){
    $spk = Spk::find($id);
    $spk-&gt;distribution_code=Input::get('distribution_code');
    $spk-&gt;destination=Input::get('destination');
    $spk-&gt;hlr=Input::get('hlr');
    $spk-&gt;first_iccid=Input::get('first_iccid');
    $spk-&gt;last_iccid=Input::get('last_iccid');
    $spk-&gt;quantity=Input::get('quantity');
    return View::make('modals.edit-spk', compact('spk'));
  }
  
  public function update($id) {
    $rules = array(
      'distribution_code' =&gt; 'required',
      'destination' =&gt; 'required',
      'hlr'=&gt; 'required',
      'first_iccid' =&gt; 'required',
      'last_iccid' =&gt; 'required',
      'quantity' =&gt; 'required'
    );
  
    $validator = Validator::make(Input::all(), $rules);
  
    if ($validator-&gt;fails()) {
      return Redirect::to('modals.edit-spk')-&gt;withErrors($validator);
    } else {
      // store
      $update = Spk::find($id);
      $update-&gt;distribution_code=Input::get('distribution_code');
      $update-&gt;destination=Input::get('destination');
      $update-&gt;hlr=Input::get('hlr');
      $update-&gt;first_iccid=Input::get('first_iccid');
      $update-&gt;last_iccid=Input::get('last_iccid');
      $update-&gt;quantity=Input::get('quantity');
      $update-&gt;save();
  
      // redirect
      Session::flash('message', 'Successfully updated SPK !');
      return Redirect::to('spk_view');
    }
  }
  </code></pre>
  
  <p>And here's the View for update the data : </p>
  
  <pre class="lang-html prettyprint-override"><code>@extends('dashboard.dashboard')
  @section('content')
  @if (Session::has('message'))
  &lt;div class="alert alert-info"&gt;{{ Session::get('message') }}&lt;/div&gt;
  @endif
  &lt;h4&gt; {{link_to('dashboard','Home');}} &gt; {{link_to('spk_view','SPK');}} &gt; Update SPK&lt;/h4&gt;&lt;hr&gt;&lt;/hr&gt;
  &lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
          Update SPK
      &lt;/div&gt;
      &lt;div class="panel-body"&gt;
          {{ Form::model($spk,array('method' =&gt; 'PUT', 'class'=&gt;'form-horizontal','route'=&gt;array('update_spk', $spk-&gt;id))) }}
          &lt;div class="form-group"&gt;
              &lt;label class="control-label col-lg-2"&gt;Distribution Code&lt;/label&gt;
              &lt;div class="col-lg-4"&gt;
                  &lt;div class="input-group"&gt;
                      &lt;input class="form-control" name ="distribution_code" type="text" data-mask="M99/99/99/9999" /&gt;
                      &lt;span class="input-group-addon"&gt;M99/99/99/9999&lt;/span&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="col-lg-5"&gt;
                  {{ $errors-&gt;first('distribution_code',
                  '&lt;div class="alert alert-danger alert-dismissable"&gt;
                  &lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                  Anda belum mengisi data dengan benar !
              &lt;/div&gt;
              ')  }}
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="form-group"&gt;
          &lt;label class="control-label col-lg-2"&gt;Destination&lt;/label&gt;
          &lt;div class="col-lg-3"&gt;
              &lt;input type="text" name="destination" class="form-control" /&gt;
          &lt;/div&gt;
          &lt;div class="col-lg-4"&gt;
              {{ $errors-&gt;first('destination',
              '&lt;div class="alert alert-danger alert-dismissable"&gt;
              &lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
              Anda belum mengisi data dengan benar !
          &lt;/div&gt;
          ')  }}
      &lt;/div&gt;
  &lt;/div&gt;
  
  &lt;div class="form-group"&gt;
      &lt;label class="control-label col-lg-2"&gt;HLR&lt;/label&gt;
      &lt;div class="col-lg-3"&gt;
          &lt;input type="text" id="hlr" name="hlr" class="form-control" /&gt;
      &lt;/div&gt;
      &lt;div class="col-lg-4"&gt;
          {{ $errors-&gt;first('hlr', 
          '&lt;div class="alert alert-danger alert-dismissable"&gt;
          &lt;button type="button" class="close" data-dismiss="alert"aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
          Anda belum mengisi data dengan benar !
      &lt;/div&gt;
      ')  }}
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;label class="control-label col-lg-2"&gt;First ICCID&lt;/label&gt;
      &lt;div class="col-lg-3"&gt;
          &lt;input type="text" id="first_iccid" name="first_iccid" class="form-control" /&gt;
      &lt;/div&gt;
      &lt;div class="col-lg-4"&gt;
          {{ $errors-&gt;first('first_iccid', 
          '&lt;div class="alert alert-danger alert-dismissable"&gt;
          &lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
          Anda belum mengisi data dengan benar !
      &lt;/div&gt;
      ')  }}
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;label class="control-label col-lg-2"&gt;Last ICCID&lt;/label&gt;
      &lt;div class="col-lg-3"&gt;
          &lt;input type="text" id="last_iccid" name="last_iccid" class="form-control" /&gt;
      &lt;/div&gt;
      &lt;div class="col-lg-4"&gt;
          {{ $errors-&gt;first('last_iccid',
          '&lt;div class="alert alert-danger alert-dismissable"&gt;
          &lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
          Anda belum mengisi data dengan benar !
      &lt;/div&gt;
      ')  }}
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt;
      &lt;label class="control-label col-lg-2"&gt;Quantity&lt;/label&gt;
      &lt;div class="col-lg-3"&gt;
          &lt;input type="text" id="quantity" name="quantity" class="form-control" /&gt;
      &lt;/div&gt;
      &lt;div class="col-lg-4"&gt;
          {{ $errors-&gt;first('quantity', 
          '&lt;div class="alert alert-danger alert-dismissable"&gt;
          &lt;button type="button" class="close" data-dismiss="alert" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
          Anda belum mengisi data dengan benar !
      &lt;/div&gt;
      ')  }}
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-actions no-margin-bottom" style="text-align:center;"&gt;
      {{ Form::submit('Update SPK', array('class' =&gt; 'btn btn-primary btn-line btn-rect')) }} 
  &lt;/div&gt;
  {{Form::close()}}
  &lt;/div&gt;
  &lt;/div&gt;
  @stop
  </code></pre>
  
  <p>This view doesn't work and it can't get the selected data from <code>$id</code> into the form. It is returning this error:</p>
  
  <blockquote>
    <p>"Undefined property: Illuminate\Database\Eloquent\Collection::$id (View: C:\XAMPP\htdocs\ims2\app\views\modals\edit-spk.blade.php)" </p>
  </blockquote>