I'm building relationships between the users and posts tables. I'm wondering if there is a way to write this differently than this syntax?
$request->user()->posts()->create([
'body' => $request->body
]);
Using syntax like this below how can achieve the same result as above?
Post::create([
'body' => $request->body,
]);
I'm curious because I like to keep the same patterns.
user_idfield to that array (which would have to be fillable on the model) ... i would suggest using the first method and let eloquent handle the needed key for the relationship