Support the ongoing development of Laravel.io →
posted 8 years ago
Eloquent
Last updated 2 years ago.
0

The table name that is used to save the data in is based on your model. The foreign key however is based on the relationship. So in your example it works because both relationships have the default key model_id. If you would rename one of the keys it wouldn't work anymore.

return $this->hasMany('App\Post', 'post_user_id');

So basically this is just a coincidence and you should make sure to use the correct relationship. :)

0

thanks! :)

0

Sign in to participate in this thread!

Eventy

Your banner here too?

pedes42 pedes42 Joined 24 Sep 2015

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.