| Viewed 19 times

How to override Eloquent foreign key of the relationship in laravel


How to override Eloquent foreign key of the relationship in laravel

1 Answer
Mohammad Qandeel
Answered
0

Yes, you can override Eloquent foreign key of the relationship in laravel bypass a second argument to the hasOne method.

As you know eloquent by default determines the foreign key of the relationship based on the model name.

if the module name is User then eloquent automatically set a user_id as a foreign key.

in the module, you can  pass a second argument to the hasOne method like 

return $this->hasOne('User\Phone', 'Your_foreign_key_name');
 


Related Questions