laravel 原生sql语句,查询构造返回以数组形式返回

是原生sql语句
2025-04-08 04:15:46
推荐回答(3个)
回答1:

$nodes = Db::table('account')->orderBy('sort', 'asc')->orderBy('id' ,'asc')->get()->map(function ($value) {
return (array)$value;
})->toArray();

回答2:

accepted

Laravel 4
In Laravel 4, you have to call DB::getQueryLog() to get all ran queries.
$queries = DB::getQueryLog();
$last_query = end($queries);

Or you can download a profiler package. I'd recommend barryvdh/laravel-debugbar, which is pretty neat. You can read for instructions on how to install in their repository.
Laravel 3
In Laravel 3, you can get the last executed query from an Eloquent model calling the static methodlast_query on the DB class.
DB::last_query();

This, however, requires that you enable the profiler option in application/config/database.php. Alternatively you could, as @dualed mentioned, enable the profiler option, in application/config/application.php or call DB::profile() to get all queries ran in the current request and their execution time.

shareimprove this answer

回答3:

网页链接