How to use a different html input name than the column name I want to save this input data to
I usually use this method because all html input names are equal to the database columns:
Model::create($request->all());
Now I know I can use this:
Model::create([ 'name' => $request->name, 'feild' = > $request=>value, etc. ]);
But I have a lot of values and I don't want to rewrite it over and over again, so is there a way to combine $request->all()
with the second method?
I found that the PHP array_merge() function can be used as follows:
One way is to add the fields using https://laravel.com /docs/9.x/collections#method-merge merge() and use https://laravel. com/docs/9.x/collections#method-only Return only fields to be added to the model, or https://laravel.com/docs/9.x/collections#method-except except() inverse