How to specify which method to use (store and update) laravel How to specify which method to use (store and update) laravel laravel laravel

How to specify which method to use (store and update) laravel


All resource controllers do for you is offer a convenient shortcut to the following:

Route::get('/resource',                 ['as' => 'resource.index',      'uses' => 'ResourceController@index'    ]);Route::get('/resource/create',          ['as' => 'resource.create',     'uses' => 'ResourceController@create'   ]);Route::post('/resource',                ['as' => 'resource.store',      'uses' => 'ResourceController@store'    ]);Route::get('/resource/{resource}',      ['as' => 'resource.show',       'uses' => 'ResourceController@show'     ]);Route::get('/resource/{resource}/edit', ['as' => 'resource.edit',       'uses' => 'ResourceController@edit'     ]);Route::put('/resource/{resource}',      ['as' => 'resource.update',     'uses' => 'ResourceController@update'   ]);Route::delete('/resource/{resource}',   ['as' => 'resource.destroy',    'uses' => 'ResourceController@destroy'  ]);

So if you call Route::resource('manage_accounts', 'ManageAccountsController') you are creating 7 routes. You're specifically telling Laravel to only create 3 of them, namely these:

Route::get('/resource',                 ['as' => 'resource.index',      'uses' => 'ResourceController@index'    ]);Route::post('/resource',                ['as' => 'resource.store',      'uses' => 'ResourceController@store'    ]);Route::put('/resource/{resource}',      ['as' => 'resource.update',     'uses' => 'ResourceController@update'   ]);

You call those three methods on your controller by requesting those route URLs, e.g. you would 'call' the index route simply by requesting it's URL:

GET http://server/resource

When I look at your markup, I see this form tag:

<form class="form-horizontal" role="form" method="POST" action="/manage_accounts" novalidate>

This will create this HTTP request when the form is submitted:

POST http://server.com/manage_accounts

Comparing that to your resource routes, this will wind up calling your controller's store() method. If you want that form to call your update() method instead, you must make a PUT request. Since HTML forms can't make PUT requests, Laravel provided a way to mimick a PUT request with forms:

<form class="form-horizontal" role="form" method="POST" action="/manage_accounts/{{ $account->id }}" novalidate>    <input type="hidden" name="_method" value="PUT" />

Also notice that the url the form is posting to has changed, and should include the ID of an actual account you want to update.

You may also find it helpful to compare this to what artisan itself sees as your available routes. You can list all of your available routes by issuing the artisan command $ php artisan route:list (Laravel 5) or $ php artisan routes (Laravel 4)


Use Store methode to create records in database. Update method use to edit records. Like example create method - register user and update method - edit profile