![](/img/trans.png)
[英]How to retrieve data settings from database array to have globally acces in Laravel 5
[英]How to retrieve data from a database as an array in Laravel?
通常,當我們使用get()
函數時,數據從 Laravel 中的數據庫中檢索為對象。 但我想以數組的形式檢索數據。
在 CodeIgnitor 中,我們使用get_array()
。 我們在 Laravel 中使用了什么?
我已經嘗試過toArray()
。 但沒有結果。
$doctor_result = Doctor::select('*')->toArray();
如何解決?
我得到了結果。 只需更改代碼
$doctor_result = Doctor::all()->toArray();
你也可以這樣做。
$result = DB::table('tableName')->get();
$resultArray = $result->toArray();
第二種方式,但有些棘手。
$resultArray = json_decode(json_encode($result), true);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.