Damien
Damien

Reputation: 1647

Laravel Resource Route destroy (DELETE) without id

Is it possible to modify Laravel's resource routing so I can direct to the destroy method without an ID? The reason being when I call destroy on my UsersController, I only want to delete the currently authenticated user, not the passed ID.

If I simply remove the $id parameter from the destroy method, I get the following error:

MethodNotAllowedHttpException in RouteCollection.php line 207

I guess I could leave the $id there, but I would really rather not require the user to pass the id in the URI.

Thanks

Upvotes: 1

Views: 2944

Answers (1)

lukasgeiter
lukasgeiter

Reputation: 152950

You can, but you have to add an additional route for that:

Route::delete('user', 'UserController@destroyAuthenticated');
Route::resource('user', 'UserController');

And then in your controller something like that:

public function destroyAuthenticated(){
    Auth::user()->delete();
}

Upvotes: 4

Related Questions