samedi 8 décembre 2018

Relationship with Auth()->user() for experienced?

Why I can't load the data model for Auth()->user()?

Users model:

public function Organization()
{
  return $this->hasOne(\App\Organization::class, 'User_Id', 'id');
}

Model Organization:

public function User()
{
  return $this->belongsTo(\App\User::class, 'id', 'User_Id');
}

Call:

$organization = Auth()->user();
$organization->load('Organization');
dd($organization->Organization()->get());

Result:

Collection {#415
  #items: []
}

The keys in the relationship between the models are correct - I checked, also in the two tables there are related entries by id = User_Id

Why then does an empty collection always return?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire