How to update a product in laravel 5,8

Posted 1 week ago by irankhosravi

I have a product I want to edit a product

Look at my codes

public function update(ProductRequest $request)
{
    $product->user_id = auth()->user()->id;
    $product->title = $request->title;
    $product->body = $request->body;
    $product->price = $request->price;

    if($request->has('image')) {
        $image = $request->file('image');
        $filename = $image->getClientOriginalName();
        $image->move(public_path('images/products'), $filename);
        $product->image = $request->file('image')->getClientOriginalName();
    }

    $product->update();

    $product->categories()->sync($request->category);

    return redirect()->route('products.index');
}

Everything changes except image.

Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.