2016年9月6日 星期二

Laravel Eloquent: How to get only certain columns from joined tables

For Laravel >= 5.2

Use the ->pluck() method
$roles = DB::table('roles')->pluck('title');
If you would like to retrieve an array containing the values of a single column, you may use the pluck method

For Laravel <= 5.1

Use the ->lists() method
$roles = DB::table('roles')->lists('title');
This method will return an array of role titles. You may also specify a custom key column for the returned array:

from : http://stackoverflow.com/questions/14727038/laravel-eloquent-how-to-get-only-certain-columns-from-joined-tables

沒有留言:

wibiya widget