所以我有以下代码...
$query = DB::table('recipes');
// USING ONE OF THE FF STATEMENTS CHANGES THE OUTPUT
$second = DB::table('recipes'); // WORKS
$second = $query; // BREAKS AND RETURNS 500 ERROR
$query->where('status', 0);
$query->where('type', 'x');
$second->where('status', 0);
$second->where('type', 'y');
return $second->union($query)->toSql(); // toSql ONLY FOR DEBUG
[我只是想尽全力解释为什么尽管分配值本质上是相同的查询生成器对象,但这仍会出错。
您的语法已关闭:
$first = DB::table('recipes')
->where('status', 0);
->where('type', 'x');
$second = DB::table('recipes')
->where('status', 0);
->where('type', 'y');
->union($first)
->get();