region pagination
parent
cbf27302e4
commit
4745c1dff4
|
|
@ -44,6 +44,7 @@ class Handler extends ExceptionHandler
|
|||
*/
|
||||
public function register()
|
||||
{
|
||||
// Laravel9.x 无法捕获 ModelNotFoundException, 在父类 prepareException 方法中被转换为 Symfony\Component\HttpKernel\Exception\NotFoundHttpException
|
||||
$this->renderable(function (\Illuminate\Database\Eloquent\ModelNotFoundException $e, Request $request) {
|
||||
if ($request->acceptsJson()) {
|
||||
return response()->json(['status' => 404, 'msg' => '资源不存在', 'data' => null], 200);
|
||||
|
|
|
|||
|
|
@ -32,6 +32,8 @@ class ArticleController extends Controller
|
|||
|
||||
$list = $query->paginate($request->input('per_page'));
|
||||
|
||||
|
||||
|
||||
return $this->json(ArticleResource::collection($list));
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -33,18 +33,31 @@ class RegionController extends Controller
|
|||
return $this->json(RegionResource::make($info));
|
||||
}
|
||||
|
||||
public function plants($id)
|
||||
public function plants($id, Request $request)
|
||||
{
|
||||
$info = Region::show()->findOrFail($id);
|
||||
$list = $info->plants()->get();
|
||||
|
||||
$query = $info->plants();
|
||||
$per = $request->input('per_page');
|
||||
if ($per == -1) {
|
||||
$list = $query->get();
|
||||
} else {
|
||||
$list = $query->paginate($per);
|
||||
}
|
||||
|
||||
return $this->json(RegionPlantResource::collection($list));
|
||||
}
|
||||
|
||||
public function harvests($id)
|
||||
public function harvests($id, Request $request)
|
||||
{
|
||||
$info = Region::show()->findOrFail($id);
|
||||
$list = $info->harvests()->get();
|
||||
$query = $info->harvests();
|
||||
$per = $request->input('per_page');
|
||||
if ($per == -1) {
|
||||
$list = $query->get();
|
||||
} else {
|
||||
$list = $query->paginate($per);
|
||||
}
|
||||
|
||||
return $this->json(PlantHarvestResource::collection($list));
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue