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

Popular posts from this blog

javascript - Slick Slider width recalculation -

jsf - PrimeFaces Datatable - What is f:facet actually doing? -

angular2 services - Angular 2 RC 4 Http post not firing -