php - Laravel 5.2 Eloquent hasOne relationship doesn't work -
i have relationship in chat model
public function user() { return $this->hasone(user::class,'id','writers_id'); }
and want use in controller. tryed many ways, no 1 worked. giving last try example (result - blank page).
print_r($chat = chat::where('id', 1)->first()->user);
can me? thanks! don't understand eloquent, used simple db query maker before, said should every database stuff in model. correct? sorry poor english!
first mentioned @vohuman
return $this->hasone('app\user', 'id', 'writers_id');
and when using it:
chat::where('id', 1)->first()->user()->first()->attribute
Comments
Post a Comment