使用 Laravel Eloquent 方法 獲取 Eloquent 呼叫查詢的第一種方法是使用 toSql() 方法。此方法在不運行的情況下回傳查詢——如果您不想更改資料而只獲取查詢,這很好——但如果您的查詢更復雜或有子查詢,則此方法不會顯示整個查詢。
在這里輸入代碼
App\User::query()
->where('created_at', '<', now()->subYear())
->with('assignedApps', 'courses')
->orderBy('email', 'asc')
->limit(5)
->toSql();
uj5u.com熱心網友回復:
如果要顯示所有查詢,則必須啟用查詢日志。 DB::enableQueryLog
\DB::enableQueryLog(); // enable the query log before your modal
App\User::query()
->where('created_at', '<', now()->subYear())
->with('assignedApps', 'courses')
->orderBy('email', 'asc')
->limit(5)
->get();
dd(DB::getQueryLog()); // after your query, dump and die get query log.
它將回傳所有帶有值的查詢結果
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/416430.html
標籤:
上一篇:在遷移時重構資料庫模式
