php - Query builder get array of results instead of objects in Laravel -


here's query

db::table('genres')         ->join('albumgenres', 'genres.id', '=', 'albumgenres.genre_id')         ->join('albums', 'albumgenres.album_id', '=', 'albums.id' )         ->select('genres.id')         ->where('albumgenres.album_id','=',$this->id)->get(); 

but this

"genre_id": [         {             "id": "4"         },         {             "id": "8"         }     ] 

what should results array

"genre_id" : [4,8] 

just use ->lists('id') instead of ->get():

db::table('genres')     ->join('albumgenres', 'genres.id', '=', 'albumgenres.genre_id')     ->join('albums', 'albumgenres.album_id', '=', 'albums.id' )     ->where('albumgenres.album_id', '=', $this->id)     ->lists('genres.id'); 

read more: http://laravel.com/docs/5.0/queries#selects (retrieving list of column values section)


Comments

Popular posts from this blog

android - MPAndroidChart - How to add Annotations or images to the chart -

javascript - Add class to another page attribute using URL id - Jquery -

firefox - Where is 'webgl.osmesalib' parameter? -