Laravel 4 retrieval -


i've got function in user model (i use laravel's default user model) relationship player model.

i want retrieve id of player, can't. there anyway it? i've tried like:

auth::user()->players->id; 

or

auth::user()->id->players; 

but doesn't work. hints?

that depends on type of relationship. code provided can guess relationship called 'players' , not 'player' (meaning should have players() function inside user model). if case, code

auth::user()->players 

returns collections of players. can loop through collection , ids of players:

foreach (auth::user()->players $player) {     $playerid = $player->id;     // more stuff single player here } 

hope clarifies things little bit. if not, please provide more details relationship between user , player models. can find more details here: http://laravel.com/docs/eloquent#relationships


Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

jquery - Fancybox - apply a function to several elements -

An easy way to program an Android keyboard layout app -