Answer the question
In order to leave comments, you need to log in
What is the error in passing/substituting data when editing a category?
When you click on the edit button (the buttons have the correct url), an error occurs
Missing required parameter for [Route: categories.update] [URI: admin_panel/categories/{category}] [Missing parameter: category]. (View: C:\OpenServer\domains\LaravelAdminPanel\resources\views\admin\categories\edit.blade.php)
Can't figure out how to pass data from CategoriesController.php (namely, edit function) to edit.blade.php form
CategoriesController.php
public function edit(Categories $categories)
{
return view('admin.categories.edit', ['categories' => $categories]);
}
<form action="{{ route('categories.update', $categories->id) }}" method="POST">
@csrf
@method('PUT')
<div class="card-body">
<div class="form-group">
<label for="title">Название</label>
<input type="text" value="{{ $categories->title }}" class="form-control" name="title" id="title" placeholder="Введите название категории" required>
</div>
Answer the question
In order to leave comments, you need to log in
I rewrote the function in my own way and it worked
public function edit(Categories $categories, $id)
{
$categories = new Categories;
$categories = $categories->find($id);
return view('admin.categories.edit', ['categories' => $categories]);
}
Categories is a model, right? Then why is it named in the plural?
You are editing the category , not the categories Model
- Category
, table - categories
Route:
Route::post('categories/{category}')->name('category.update');
public function edit(Category $category)
{
return view('admin.category.edit', ['category' => $category]);
}
<form action="{{ route('category.update', $category) }}"
method="POST"
>
There is a naming convention in laravel that should be followed. Then the magic of the framework will start working.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question