I would like to know how it is possible to merge data from Input::all()
with a model and save the result.
To clarify: I would like to do something like below:
$product = Product::find(1); // Eloquent Model
$product->merge( Input::all() ); // This is what I am looking for :)
$product->save();
You should use update
method:
$product->update(Input::all());
But I recommend to use only
method instead
$product->update(Input::only('name', 'type...'));
Use the model's fill()
method for greater control. This lets us change attributes after merging the values before we save:
$product->fill($request->all());
$product->foo = 'bar';
$product->save();
If we've properly defined the model's $fillable
attributes, there's no need to use Input::only(...)
(or $request->only(...)
in newer versions).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With