我正在使用Laravel 5.2。我想用两个部分写一个查询:
$getData = DB::table($table)
->where($where);
$getData->first();
return $getData;
但它不适合我。它没有向我提供正确的数据。
它给出了:
Array ( [aggregate] => [columns] => [distinct] => [from] => countries [joins] => [wheres] => Array ( [0] => Array ( [type] => Nested [query] => Array ( [aggregate] => [columns] => [distinct] => [from] => countries [joins] => [wheres] => Array ( [0] => Array ( [type] => Basic [column] => country_name [operator] => = [value] => India [boolean] => and ) ) [groups] => [havings] => [orders] => [limit] => [offset] => [unions] => [unionLimit] => [unionOffset] => [unionOrders] => [lock] => ) [boolean] => and ) ) [groups] => [havings] => [orders] => [limit] => 1 [offset] => [unions] => [unionLimit] => [unionOffset] => [unionOrders] => [lock] => )
但是当我这样打电话时它能正常工作:
$getData = DB::table($table)
->where($where)->first();
return $getData;
我们不能在laravel中分两部分调用查询。
答案 0 :(得分:1)
您必须从$getData->first();
$getData = DB::table($table)
->where($where);
$getData = $getData->first(); // <----
return $getData;