Answer the question
In order to leave comments, you need to log in
How to set default field values in eloquent model?
Is it possible to set default values right inside the App\Post model, for example, for the user_id field of the type: 'user_id'=>auth()->user()->id;
so that when creating a record, the current user's id is automatically entered into the table and this would not need to be specified in the create method?
Answer the question
In order to leave comments, you need to log in
What you want is done through communication.
Auth::user()->posts()->create([
'title' => 'New Post',
]);
It is possible, but not necessary, especially if you do not know how.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question