转换laravel对象为js数组


Convert laravel object to js array

我是新来的。如何将laravel对象转换为js数组。

$customer = new Customer();             
$result = $customer->where('client_state','like', '%'.$statename.'%')->get(array('client_state'));
echo $result;

结果是……

[{"client_state":"Gujarat1"},{"client_state":"Gujarat"}]

但我需要这样的…

["Gujarat1","Gujarat"]

这怎么可能?

如果您希望查询返回一个值设置为首选列值的数组,那么您将使用方法lists('your_column_here')而不是get()

Try this:

$result = $customer->where('client_state','like', '%'.$statename.'%')->lists('your_column'));

此处参考:http://laravel.com/docs/5.0/queries#selects