I know that this question may be duplicated, but no current solution helped me to figure out the problem !
I have 2 models: User and Account, where user can have multiple accounts, but an account should belong to only one user.
Here the relations in the models:
In User:
class User extends Model {
public $table = 'users';
public function accounts()
{
return $this->hasMany(Account::class, 'user_id');
}
}
In Account:
class Account extends Model {
public $table = 'accounts';
public function user()
{
return $this->belongsTo(User::class,'user_id','id');
}
}
When I do User::find(1) it returns null, despite I have a user in my database with the id 1.
The same Problem when I do Account::find(1)->user it returns null, but Account::find(1) works fine.
Any solution?
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2zzS9o7
via IFTTT
Aucun commentaire:
Enregistrer un commentaire