I have 2 tables Users, Organization
- Users hasMany Organization
- Organization belongsTo User
User.php
public function organization()
{
return $this->hasMany(Organization::class, 'user_id');
}
Organization.php
public function user(){
return $this->belongsTo(Organization::class,'user_id');
}
Now I want to retrieve data of Organization with user
In Controller
dd( Organization::with('user')->get() );
but in relation, user returns null. what should I do now? Please help
In the
Organization
model theuser
relationship should be abelongsTo
withUser
notOrganization
(self).Then you can load that relationship on
Organization
: