Answer the question
In order to leave comments, you need to log in
I get an error Route [post.destroy] not defined, what should I do?
I want to delete a post by a button, but I get an error that such a route does not exist.
show.blade.php:
@extends('layouts.main')
@section('content')
<div class="post">
<h3 class="post-title">{{$post->title}}</h3>
<a href="{{route('post.store')}}">back</a>
<a href="{{route('post.edit', $post->id)}}">edit</a>
<form method="POST" action="{{route('post.destroy', $post->id)}}">
@method('DELETE')
@csrf
<input type="submit" value="delete">
</form>
</div>
@endsection
Route::get('/', function () {return view('main');})->name('main.index');
Route::get('/posts', '[email protected]')->name('post.index');
Route::get('/posts/create', '[email protected]')->name('post.create');
Route::post('/posts', '[email protected]')->name('post.store');
Route::get('/posts/{post}', '[email protected]')->name('post.show');
Route::get('/posts/{post}/edit', '[email protected]')->name('post.edit');
Route::patch('/posts/{post}', '[email protected]')->name('post.update');
Route::delete('/posts/{post}', '[email protected]')->name('post.destroy');
public function destroy(Post $post) {
$post->delete();
return redirect()->route('post.index');
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question