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();
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();
Please note, the option presented below is apparently no longer supported as of Laravel 5.4 (thanks @Alex).
In Laravel 5.3 and below, there is a method to set the fetch mode for select queries.
In this case, it might be more efficient to do:
That way, you won't waste time creating objects and then converting them back into arrays.