jeudi 3 septembre 2015

Laravel 5 Eloquent relationship: getting the data

This is a noobie question...

My table

Users -id -username -password

Group -userid -groupname

My models

Users(model) -hasOne(Group)

Group(model) -belongsTo(Users)

If i do this;

$userdetails = \App\Users::find(1);

I only get user info.

I need to do this to get the group;

$group = $userdetails->group;

It doesnt seems elegent to have two different variable to send to the view. Is there any better way?

Thanks!



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/1ikVkCh
via IFTTT

Aucun commentaire:

Enregistrer un commentaire