I use the Laravel 5.2 framework.
I have a Model called template
. There are user specific layout options.
Now I want get the templates easy with
$template = App\Template::where('userid', Auth::user->id);
But if I want to add these templates I have a little problem.
App\Template::create(Request::all());
Doesnt work, because the Request has no userid
What is the typical way to save a new object with the userid?
You can just merge the Request array with an array containing the user ID. Like so:
App\Template::create(array_merge(Request:all(), array('user_id' => Auth::user->id)));