I
I
igordata12020-09-10 07:53:39
Laravel
igordata1, 2020-09-10 07:53:39

Why the category is not removed and writes 404?

public function destroy($id)
    {
        $category = Category::find($id);
        $category->delete();

        return redirect('/categories')->with('a', "Категория номер $id удалёна");
    }

Route::get("/categories/category/destroy/{category}", "[email protected]");


<a href="/categories/category/delete/{{$category->id}}" class="card-link">удалить</a>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexey Ukolov, 2020-09-11
@igordata1

get("/categories/category/destroy/{category}"
href="/categories/category/delete/{{$category->id}}"
Come on, eprst ... Try yourself in aeromodelling.

V
Vladimir Kokhan, 2020-09-10
@SkazochNick

In your case, you need to write
$category = new Category::find($id);
Category:::find($id)->delete();

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question