N
N
Nurislam32372022-01-24 19:28:15
Laravel
Nurislam3237, 2022-01-24 19:28:15

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


web.php:
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');


PostController.php:
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

1 answer(s)
M
mrMirik, 2022-01-25
@Nurislam3237

try

php artisan route:list
if there is no such route there, then there is a problem with caches. php
artisan route:clear
this should help

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question