DB查询构建器toArray()Laravel 4 [英] DB query builder toArray() laravel 4

查看:466
本文介绍了DB查询构建器toArray()Laravel 4的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用方法toArray()将查询转换为数组,但不适用于查询生成器.有任何转换想法吗?

I'm trying to convert a query to an array with the method toArray() but it doesn't work for the query builder. Any ideas for convert it?

示例

DB::table('user')->where('name',=,'Jhon')->get()->toArray();

推荐答案

toArray是Eloquent的模型方法,因此您需要一个Eloquent模型,请尝试以下操作:

toArray is a model method of Eloquent, so you need to a Eloquent model, try this:

 User::where('name', '=', 'Jhon')->get()->toArray();

http://laravel.com/docs/eloquent#collections

这篇关于DB查询构建器toArray()Laravel 4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆