更新到laravel 10后,我不能像这样执行原始查询:
$statement = 'SELECT';
foreach ($tables = collect(availableTables()) as $name => $table_name) {
if ($tables->last() == $table_name) {
$statement .= "( SELECT COUNT(*) FROM $table_name) as {$table_name}";
}
else {
$statement .= "( SELECT COUNT(*) FROM $table_name) as {$table_name}, ";
}
}
$query = DB::select(DB::raw($statement));
这将返回以下错误:
PDO::prepare (): Argument #1 ($query) must be of type string, Illuminate\Database|Query\ Expression given
我应该怎么做来解决这个问题
1条答案
按热度按时间ukdjmx9f1#
您不需要在
DB::select()
中使用DB::raw()
:因此,您可以使用以下代码代替: