简体   繁体   中英

How to retrieve data from a database as an array in Laravel?

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?

I got result. just change the code

$doctor_result = Doctor::all()->toArray();

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);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM