Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

can I use route() to make a DELETE request in laravel

I'm using laravel and trying to delete something. Is it possible to specify the DELETE method on laravel's route()??

e.g

route('dashboard-delete-user', ['id' => $use->id, 'method'=> 'delete'])

or something like that??

EDIT: What I meant was could I specify that in a link or a button in my blade template. Similar to this:

href="{{ route('dashboard-delete-user') }}
like image 251
Suemayah Eldursi Avatar asked Feb 01 '26 05:02

Suemayah Eldursi


1 Answers

Yes, you can do this:

Route::delete($uri, $callback);

https://laravel.com/docs/master/routing#basic-routing

Update

If for some reason you want to use route only (without a controller), you can use closure, something like:

Route::get('delete-user/{id}', function ($id) {
    App\User::destroy($id);
    return 'User '.$id.' deleted';
});
like image 154
Alexey Mezenin Avatar answered Feb 03 '26 05:02

Alexey Mezenin



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!