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();
If you prefer to use Query Builder instead of Eloquent here is the solutions
$result = DB::table('user')->where('name',=,'Jhon')->get();
First Solution
$array = (array) $result;
Second Solution
$array = get_object_vars($result);
Third Solution
$array = json_decode(json_encode($result), true);
hope it may help