Search code examples
laravelphp-7laravel-5.7laravel-controller

Laravel can I add two update method on a resource controller


I'm new to laravel and I would like to add another Update method from the created resource controller UsersController. something like this:

  public function update(Request $request, $id)
{
    "logic here"
}
  public function update2(Request $request, $id)
{
    "logic here"
}

but i do not know how to access "update2". is there a way to do this?


Solution

  • You would only need add another route to your routes/web.php file. For example:

    Route::post('/users/{user}/update2', 'UsersController@update2');
    

    As you've mentioned it being a resource controller, you may have already added something similar to:

    Route::resource('users', 'UsersController');
    

    This will create the corresponding index, show, store, update, and destroy routes.