Answer the question
In order to leave comments, you need to log in
Relationship with Auth()->user() for the experienced?
Why can't load the data model for Auth()->user()
?
Model Users:
public function Organization()
{
return $this->hasOne(\App\Organization::class, 'User_Id', 'id');
}
public function User()
{
return $this->belongsTo(\App\User::class, 'id', 'User_Id');
}
$organization = Auth()->user();
$organization->load('Organization');
dd($organization->Organization()->get());
Collection {#415
#items: []
}
Answer the question
In order to leave comments, you need to log in
This is how you write what you want to write. According to the idea, if everything is done correctly, you should bring the organization
$user = Auth()->user();
$user->load('Organization');
dd($user->Organization);
load() is lazy loading. This means that you must have a collection in your $organization before using load.
And something tells me it's not.
Maybe I misunderstood something in your code, then here is a link to the documentation: https://laravel.ru/docs/v5/eloquent-relationships#...
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question