There are two models:
class User extends Authenticatable { public function verifyUser() { return $this->hasOne('AppVerifyUser'); } } class VerifyUser extends Model { protected $guarded = []; public function user() { return $this->belongsTo('AppUser', 'user_id', 'id'); } }
I retrieve specific user:
$verifyUser = VerifyUser::where('token', $token)->first(); if ($verifyUser) { // dd($verifyUser); // not empty object dd($verifyUser->user); // null }
Why I get user
relation as null?
Advertisement
Answer
replace
return $this->belongsTo('AppUser', 'user_id', 'id');
by
return $this->belongsTo('AppUser', 'id');
or
return $this->belongsTo('AppUser');