I have two tables, posts and users . The posts table has a relationship with the users table through the user_id column.
The question is this: in the controller I'm using a merge to populate the user_id with the id of the user. I would like to know if this merge can be overridden, perhaps by using the user (belongsTo) method of the Post model. See the code:
Controller:
$request->merge(['user_id' => \Auth::user()->id]);
Post::create($request->all());
Model Post:
public function user()
{
return $this->belongsTo('App\Models\User');
}