【发布时间】:2018-10-05 04:20:00
【问题描述】:
我是 Resfully 服务和 Lumen(Laravel 微框架)的新手。
我想将 /books?limit=10&offset=5 参数传递给控制器并将其设置在 json 响应中,但我不知道如何。
web.php
$router->get('/books/', ['uses' => 'BooksController@index']);
BooksController.php
public function index()
{
$books = PartnersBooks::where('is_direct', '=', 1)
->with('direct')
->whereHas('direct', function ($query) {
$query->enable()
->select(['id', 'book_id', 'name', 'devices', 'flow', 'restrictions', 'countries', 'targeting']);
})
->offset(5) // This should have an default value until the user pass a value through url
->limit(30) // This should have an default value until the user pass a value through url
->orderBy('id', 'asc')
->get(['id', 'category', 'description']);
$status = !is_null($books) ? 200 : 204;
return response()->json($books, $status);
}
你能帮帮我吗?
谢谢,
【问题讨论】:
标签: php laravel eloquent lumen