我在屏幕截图中显示代码,因为我想向你们展示我的第 43 行
实际代码在这里:
public function index()
{
$inputs = Request::all();
$interval = '';
if(array_key_exists('interval', $inputs)){
$interval = $inputs['interval'];
}
switch ($interval) {
case 'day':
$visitors = Visitor::where('created_at', '>', now()->today())->paginate(20);;
break;
case 'week':
$visitors = Visitor::where('created_at', '>', now()->subMonth())->paginate(20);;
break;
case 'month':
$visitors = Visitor::where('created_at', '>', now()->subMonth())->paginate(20);;
break;
case 'year':
$visitors = Visitor::where('created_at', '>', now()->subYear())->paginate(20);
break;
default:
$visitors = Visitor::orderBy('updated_at', 'desc')->paginate(20);
break;
}
return View::make('layouts.be.visitors.index', get_defined_vars());
}
我参观
http://app.test/visitor?interval=year
如你看到的
Laravel Debugbar 检测到我在线进行了 2 次查询43
为什么是 2?这是预期的吗?
我可以将其改进为 1 吗?
请指教