国产+高潮+在线,国产 av 仑乱内谢,www国产亚洲精品久久,51国产偷自视频区视频,成人午夜精品网站在线观看

請問webman默認使用的laravel數(shù)據(jù)庫組件,查詢結(jié)果不支持轉(zhuǎn)成數(shù)組么?

Forsend
Db::table('user')->where('id', $id)->first()->toArray();

這樣使用會報錯,Call to undefined method stdClass::toArray()
但是我看IDE提示,有這個方法
截圖

3016 4 0
4個回答

= - =

你是用的 DB::table()->first() 查詢,返回的結(jié)果是 stdClass。stdClass 不支持 toArray 操作。

  • Forsend 2022-08-23

    請問用什么方式查詢,可以獲取數(shù)組,或者轉(zhuǎn)成數(shù)組

  • = - = 2022-08-24

    (array) DB::table()->first() 這樣會直接轉(zhuǎn)數(shù)組。stdClass 支持這種轉(zhuǎn)換。

    你可以考慮使用 laravel 的 orm model 進行查詢,查詢結(jié)果支持調(diào)用 ->toArray()

nitron

用QueryBuilder才有toArray()

timeless-zyg

DB返回就是數(shù)組
模型返回的是對象可以toArray()

  • 暫無評論
Dalong

直接轉(zhuǎn)數(shù)組 : $arr = (array)Db::table("xxxx")->where("id",1)->first();

  • 暫無評論
年代過于久遠,無法發(fā)表回答
??