title: How to specify which method to use (store and update) laravel
body: <p>So basically I have a store function and update function in my controller.php and was wondering how do I specify which method to used when needed. My progress of code is as shown below. Anyone has a solution for this?</p>
  
  <p>routes.php</p>
  
  <pre><code>Route::resource('manage_accounts', 'ManageAccountsController',
                  ['only' =&gt; ['index', 'store', 'update']]);
  </code></pre>
  
  <p>view.blade.php</p>
  
  <pre><code> &lt;button class="btn btn-sm btn-warning" type="button"
            data-toggle="modal" data-target="#register" value="{{ $user-&gt;id }}"&gt;Edit&amp;nbsp;&lt;i class="glyphicon glyphicon-edit"&gt;&lt;/i&gt;&lt;/button&gt;
   &lt;button type="button" class="btn btn-info btn-md" data-toggle="modal" data-target="#register"&gt;Register New User&lt;/button&gt;
  
   &lt;!-- Modal --&gt;
      &lt;div id="register" class="modal fade" role="dialog"&gt;
          &lt;div class="modal-dialog"&gt;
  
              &lt;!-- Modal content--&gt;
              &lt;div class="modal-content"&gt;
                 &lt;div class="modal-header"&gt;
                    &lt;button type="button" class="close" data-dismiss="modal"&gt;&amp;times;&lt;/button&gt;
                    &lt;h4 class="modal-title"&gt;User Information&lt;/h4&gt;
                &lt;/div&gt;
                &lt;div class="modal-body"&gt;
                    &lt;form class="form-horizontal" role="form" method="POST" action="/manage_accounts" novalidate&gt;
                     &lt;input type="hidden" name="_token" value="{{ csrf_token() }}"&gt;
                     &lt;div class="form-group"&gt;
                      &lt;label class="control-label col-sm-3" for="name"&gt;Username:&lt;/label&gt;
                      &lt;div class="col-sm-5 @if ($errors-&gt;has('name')) has-error @endif"&gt; 
                         &lt;input type="text" class="form-control" type="hidden" id="name" name="name" placeholder="Enter username"&gt;
                         @if ($errors-&gt;has('name')) &lt;p class="help-block"&gt;{{ $errors-&gt;first('name') }}&lt;/p&gt; @endif
                     &lt;/div&gt;
                 &lt;/div&gt;
                 &lt;div class="form-group"&gt;
                  &lt;label class="control-label col-sm-3" for="password"&gt;Password:&lt;/label&gt;
                  &lt;div class="col-sm-5 @if ($errors-&gt;has('password')) has-error @endif"&gt; 
                     &lt;input type="password" class="form-control" type="hidden" id="password" name="password" placeholder="Enter login password"&gt;
                     @if ($errors-&gt;has('password')) &lt;p class="help-block"&gt;{{ $errors-&gt;first('password') }}&lt;/p&gt; @endif
                 &lt;/div&gt;
             &lt;/div&gt;
             &lt;div class="form-group"&gt;
              &lt;label class="control-label col-sm-3" for="password_confirm"&gt;Confirm Password:&lt;/label&gt;
              &lt;div class="col-sm-5 @if ($errors-&gt;has('password_confirm')) has-error @endif"&gt; 
                 &lt;input type="password" class="form-control" type="hidden" id="password_confirm" name="password_confirm" placeholder="Re-type password again"&gt;
                 @if ($errors-&gt;has('password_confirm')) &lt;p class="help-block"&gt;{{ $errors-&gt;first('password_confirm') }}&lt;/p&gt; @endif
             &lt;/div&gt;
         &lt;/div&gt;
         &lt;div class="form-group"&gt;
          &lt;label class="control-label col-sm-3" for="email"&gt;Email:&lt;/label&gt;
          &lt;div class="col-sm-5 @if ($errors-&gt;has('email')) has-error @endif"&gt; 
             &lt;input type="email" class="form-control" type="hidden" id="email" name="email" placeholder="Enter email address"&gt;
             @if ($errors-&gt;has('email')) &lt;p class="help-block"&gt;{{ $errors-&gt;first('email') }}&lt;/p&gt; @endif
         &lt;/div&gt;
     &lt;/div&gt; 
     &lt;div class="form-group"&gt;
      &lt;label class="control-label col-sm-3" for="mobile"&gt;Phone Number:&lt;/label&gt;
      &lt;div class="col-sm-5 @if ($errors-&gt;has('mobile')) has-error @endif"&gt; 
         &lt;input type="hpnum" class="form-control" type="hidden" id="mobile" name="mobile" placeholder="Enter handphone number"&gt;
         @if ($errors-&gt;has('mobile')) &lt;p class="help-block"&gt;{{ $errors-&gt;first('mobile') }}&lt;/p&gt; @endif
     &lt;/div&gt;
  &lt;/div&gt;
  &lt;!--&lt;div class="form-group"&gt;
      &lt;label class="control-label col-sm-3" for="officeEx"&gt;Office Extension:&lt;/label&gt;
          &lt;div class="col-sm-5"&gt; 
              &lt;input type="officeEx" class="form-control" id="officeEx" placeholder="Enter office extension"&gt;
          &lt;/div&gt;
      &lt;/div&gt; --&gt;                                                                                                                     
     &lt;div class="form-group"&gt;
      &lt;label class="control-label col-sm-3" for="role_id"&gt;Role:&lt;/label&gt;
      &lt;div class="col-sm-5"&gt;
          &lt;select class="form-control" type="hidden" id="role_id" name="role_id"&gt;
              @foreach ($roles as $role)
              &lt;option value="{{ $role-&gt;id }}"&gt;{{ $role-&gt;role_description }}&lt;/option&gt;
              @endforeach
          &lt;/select&gt;
      &lt;/div&gt;
  &lt;/div&gt;
  &lt;div class="form-group"&gt; 
      &lt;div class="col-sm-offset-3 col-sm-5"&gt;
         &lt;button type="submit" class="btn btn-default"&gt;Update&lt;/button&gt;
     &lt;/div&gt;
  &lt;/div&gt;
  &lt;/form&gt;
  &lt;/div&gt;
  &lt;div class="modal-footer"&gt;
      &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>controller.php</p>
  
  <pre><code>class ManageAccountsController extends Controller
  {
      public function index() 
      {
          $users = User::orderBy('name')-&gt;get();
          $roles = Role::all();
  
          return view('manage_accounts', compact('users', 'roles'));
      }
  
      public function store(StoreNewUserRequest $request)
      {
          // create the data for new user
          $user = new User;
          $user-&gt;name     = Input::get('name');
          $user-&gt;email    = Input::get('email');
          $user-&gt;password = Hash::make(Input::get('password'));
          $user-&gt;mobile   = Input::get('mobile');
          $user-&gt;role_id  = Input::get('role_id');
  
          // save new user
          $user-&gt;save();
  
          Session::flash('flash_message', 'User successfully added!');
  
          return redirect()-&gt;back();
      }
  
      public function update($id)
      {
          // update existing user
          $user = User::findOrFail($id);
  
          $user-&gt;name     = Input::get('name');
          $user-&gt;email    = Input::get('email');
          $user-&gt;password = Hash::make(Input::get('password'));
          $user-&gt;mobile   = Input::get('mobile');
          $user-&gt;role_id  = Input::get('role_id');
  
          // save existing user
          $user-&gt;save();
  
      }
  }
  </code></pre>