Laravel Eloquent: Merge Model with Input

I would like to know how to combine 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();
+4
source share
3 answers

You should use the method update:

$product->update(Input::all());

But I recommend using the onlymethod instead

$product->update(Input::only('name', 'type...'));
+3
source

In addition to Razor's answer, if you need to create a new model, you can use:

$product = Product::create(Input::all());
0
source

fill() . :

$product->fill($request->all());
$product->foo = 'bar';
$product->save();

$fillable , Input::only(...) ( $request->only(...) ).

0

Source: https://habr.com/ru/post/1544300/


All Articles