This method doesn't work:
public function update(Category $category) {
$data = request()->validate([
'name' => 'required',
]);
$category->update([
$data
]);
return redirect("/category/{$category->id}/edit");
}
But it works fine, like that:
public function update(Category $category) {
$data = request()->validate([
'name' => 'required',
]);
$category->update([
'name' => request()->input('name')
]);
return redirect("/category/{$category->id}/edit");
}
Result from dd($data)
in first case is :
array:1 [▼
"name" => "test"
]
I'm using first way in other conrollers and it also works, I'm confused.
My Answer:
A model in PHP is a class that represents the data and business logic of an application. It typically interacts with a database to retrieve and manipulate data, and may also contain methods for performing calculations or other operations on the data. Models are an important part of the MVC (Model-View-Controller) design pattern, which helps to separate the concerns of an application and improve code organization and maintainability.
Rate this post
4 of 5 based on 9152 votesComments