I am trying to delete a record but when I press delete button it takes me to a white screen.
index.blade.php
<form>
@csrf
@method('DELETE')
<button type="submit" formaction="{{ route('user.destroy',$user->id) }}">Delete</button>
</form>
Controller destroy function
public function destroy(User $user)
{
User::findOrfail($user->id)->delete();
return redirect()->route('user.index')->with('success','Record Deleted Successfully!!!');
}
Route
Route::resource('/onemany/user',UserController::class);
Route List for the project
I am trying to delete the record. Tried using anchor tag also but getting same result with it.
>Solution :
Most probably, the problem will occur at the route name and it wont enter the controller method at all.
You could do php artisan route:list and find out the correct route name.
Edit:
<form action="{{ route('user.destroy',$user->id) }}" method="Post">
@csrf
@method('DELETE')
<button type="submit" class="btn btn-danger">Delete</button>
</form>