B
B
BonBon Slick2016-11-27 15:43:38
Laravel
BonBon Slick, 2016-11-27 15:43:38

How to take everything from Request and add 1 field on Insert in Laravel 5.3?

This code takes everything:
$product = new Product($request->all());
You can of course break it down, take everything by type:

$product = new Product([
'name' => $request->name,
'description' => $request->name,
...
]);

Or make 2 save requests.
Only then there will be a lot of visual code, I would like to make it easier.
How can I take $request->all() + another parameter and create an object with this data?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Evgeny Perin, 2016-11-27
@BonBonSlick

Product::create($request->all() + ['key' => 'value']);

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question