Laravel 查询 returns 生成器而不是集合
Laravel query returns builder instead of collection
我是 laravel 的新手,正在尝试获得结果。
我的代码是这样的:
class GegonosController extends Controller
{
public function index($gid = null, $cid = null, $nid = null)
{
if (is_null($cid) and is_null($nid) and is_null($gid)) {
$gegon = Gegono::orderBy('created_at','desc')->get();
}
else{
if(!is_null($gid)) {
if($gid == 0) {
$gegon = Gegono::where('gegtype_id','>',1);
}
else{
$gegon = Gegono::where('gegtype_id', '=', $gid);
}
}
else {
$gegon = Gegono::where('gegtype_id','>',0);
}
if (!is_null($cid)) {
$gegon->where('city_id', '=',$cid);
}
if (!is_null($nid)) {
$gegon->where('nomos_id','=', $nid);
}
$gegon->orderBy('created_at','desc')->get();
}
$nomoi = \App\Nomoi::orderby('name')->get();
return view('front.gegonota', compact('gegon','gid','cid','nid','nomoi'));
}
首先,如果当所有变量都为空时,结果是table的所有记录的集合。
在所有其他情况下,如果(其他情况)结果是生成器而我没有得到任何结果,
它没有显示任何错误,但没有给出任何结果。
任何帮助都会为我节省很多时间。
查询生成器的 get()
方法 returns 记录集合。在你的代码中,你只是在空中调用 get()
方法,所以它什么都不做。您应该将其分配给变量或在表达式中使用它。
我是 laravel 的新手,正在尝试获得结果。 我的代码是这样的:
class GegonosController extends Controller
{
public function index($gid = null, $cid = null, $nid = null)
{
if (is_null($cid) and is_null($nid) and is_null($gid)) {
$gegon = Gegono::orderBy('created_at','desc')->get();
}
else{
if(!is_null($gid)) {
if($gid == 0) {
$gegon = Gegono::where('gegtype_id','>',1);
}
else{
$gegon = Gegono::where('gegtype_id', '=', $gid);
}
}
else {
$gegon = Gegono::where('gegtype_id','>',0);
}
if (!is_null($cid)) {
$gegon->where('city_id', '=',$cid);
}
if (!is_null($nid)) {
$gegon->where('nomos_id','=', $nid);
}
$gegon->orderBy('created_at','desc')->get();
}
$nomoi = \App\Nomoi::orderby('name')->get();
return view('front.gegonota', compact('gegon','gid','cid','nid','nomoi'));
}
首先,如果当所有变量都为空时,结果是table的所有记录的集合。 在所有其他情况下,如果(其他情况)结果是生成器而我没有得到任何结果,
它没有显示任何错误,但没有给出任何结果。
任何帮助都会为我节省很多时间。
查询生成器的 get()
方法 returns 记录集合。在你的代码中,你只是在空中调用 get()
方法,所以它什么都不做。您应该将其分配给变量或在表达式中使用它。