Search code examples
phplaravel-4query-builder

DB query builder toArray() laravel 4


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?

Example

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

Solution

  • 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