route link
<a href="{{ route('users.destroy', $user->id) }}">Delete</a>
define route
Route::resource('users', UserController::class);
controller function
public function destroy($id)
{
$delete = DB::table('users')->delete($id);
if ($delete) {echo 'success';}
}
CodePudding user response:
in the delete
route, the method should be delete
, you can write it in this way
<form action="{{ route('users.destroy', $user->id) }}" method="post">
@csrf
@method('delete')
<button type="submit">Delete</button>
</form>
CodePudding user response:
first of all you need to find specific id then delete the same one
$user = User::findOrFail($id);
$user ->delete();