I've made a small laravel project but the delete method is nog working:
I use a resource controller my route is :
Route::resource('roles','Admin\RoleController');
in my view I have
<form action="{{route('roles.destroy',$role->id)}}" style="display:inline">
@method('delete')
@csrf
<button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i></button>
</form>
But when i click the button it will show me the role ( = get method of the resource ) What am I doing wrong ?
If you're using Laravel 5.1 or later
<form action="{{ route('roles.destroy', 'YOUR_ID') }}" method="POST">
{{ method_field('DELETE') }}
{{ csrf_field() }}
<button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i></button>
</form>
If you're using Laravel 5.6 or later
<form action="{{ route('roles.destroy', 'YOUR_ID') }}" method="POST">
@method('DELETE')
@csrf
<button type="submit" class="btn btn-danger"><i class="fa fa-trash"></i></button>
</form>
You can read more about method spoofing in Laravel Documentation.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With