@lizzie
To make a delete request in Laravel, you can use Laravel's built-in methods and HTTP verbs. Here is an example of how to make a delete request in Laravel:
1
|
Route::delete('/posts/{id}', 'PostController@destroy'); |
1 2 3 4 5 6 7 |
public function destroy($id) { $post = Post::findOrFail($id); $post->delete(); return redirect('/posts')->with('success', 'Post deleted successfully'); } |
1 2 3 4 5 |
<form action="{{ url('/posts/'.$post->id) }}" method="POST"> @csrf @method('DELETE') <button type="submit">Delete Post</button> </form> |
This is a basic example of how to make a delete request in Laravel. Remember to always use proper validation and authorization checks to ensure that only authorized users can delete records.