There are two models:
JavaScript
x
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:
JavaScript
$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
JavaScript
return $this->belongsTo('AppUser', 'user_id', 'id');
by
JavaScript
return $this->belongsTo('AppUser', 'id');
or
JavaScript
return $this->belongsTo('AppUser');