我个人觉得是否应该对该教程中的 Request 类的引用位置做一个提示?
个人觉得应该对Request类的引用位置做一个提示,代码如下,不然初学者容易犯迷糊
use Dingo\Api\Contract\Http\Request; //个人觉得应该补上这个引用的提示
public function index(Request $request, Topic $topic)
{
$query = $topic->query();
if ($categoryId = $request->category_id) {
$query->where('category_id', $categoryId);
}
// 为了说明 N+1问题,不使用 scopeWithOrder
switch ($request->order) {
case 'recent':
$query->recent();
break;
default:
$query->recentReplied();
break;
}
$topics = $query->paginate(20);
return $this->response->paginator($topics, new TopicTransformer());
}
推荐文章: