Reputation: 624
Normally data retrieved as an object from database in Laravel when we use get()
function. But I want to retrieved data as an array.
In CodeIgnitor we use get_array()
. What we use in Laravel ?
I have already tried with toArray()
. But no result.
$doctor_result = Doctor::select('*')->toArray();
How to solve that?
Upvotes: 1
Views: 13527
Reputation: 3516
You can get data from base
query builder without any unnecessary transformation.
$doctor_result = Doctor::select('*')->toBase()->get()
This will give you array of stdClass
usually ( base on PDO config ).
Upvotes: 0
Reputation: 692
You can also do like this.
$result = DB::table('tableName')->get();
$resultArray = $result->toArray();
second way, but some tricky.
$resultArray = json_decode(json_encode($result), true);
Upvotes: 1
Reputation: 624
I got result. just change the code
$doctor_result = Doctor::all()->toArray();
Upvotes: 4