1 year ago

Update vs Save model after form validation

Posted 1 year ago by octal

Hello, I'm having a strange behaviour (or I didn't understood something in laravel doc).

I have a simple form that has a PATCH action that trig my controller update method. The code is the following (simplified)

 public function update(Request $request, Product $product)
        $attributes = $request->validate(
                'label'       => ['required', 'min:3'],
                'description' => [],
                'category'    => []

        return redirect("/products/{$prodcut->id}");

I have put all my three attributes in the $fillable field of my Product model.

When I use this code, everything works as exected (the model is updated). If I replace the $product->update with $product->save($attributes) the rediection occurs correctly and everything seems to work as expected, but when I check my database, the model is NOT UPDATED at all.

What's the real difference between save and update ????? what am I missing here?

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