When i run the update controller it gives me this error, i tried different solution from this same platform with this error but their fix was to update with separated syntax of save($product) like that. I am using Model Store for authentication and saving the data or editing deleting.
"Type error: Argument 1 passed to Illuminate\Database\Eloquent\Relations\HasOneOrMany::save() must be an instance of Illuminate\Database\Eloquent\Model, array given, called in C:\xampp\htdocs\shopping\app\Http\Controllers\ProductController.php on line 138 ◀"
Update Method
public function update(Request $request, Product $Product){
$store = Store::where('user_id', Auth::user()->id)->first();
$updateProduct = $store->product()->save([
'name'=> $request->input('name'),
'description' => $request->input('description'),
'normal_price' => $request->input('normal_price'),
'sale_price' => $request->input('sale_price'),
'category_id' => $request->input('category_id'),
]);
return redirect('product')->with('status', 'Product Updated');
}
View Edit Form
<form method="post" action="{{route('product.update', $product->id)}}">
{{ csrf_field() }}
{{ method_field('PUT') }}
create()instead ofsave()- Hiren Gohelcreate()is for creating a new product! If you want to update a product, then useupdate()! - Hiren GohelProduct::where('id', $id)->update([ 'name'=> $request->input('name'), 'description' => $request->input('description'), 'normal_price' => $request->input('normal_price'), 'sale_price' => $request->input('sale_price'), 'category_id' => $request->input('category_id'), ]);- Hiren Gohel