为什么做超过7天总是出错?
public function paginated(Request $request)
{
$fromDate = $request->fromDate ? Carbon::parse($request->fromDate) : Carbon::now();
$toDate = $request->toDate ? Carbon::parse($request->toDate) : Carbon::now();
$query = Vehicle::paginate(10);
->with('class')
->with(['status' => function ($query) {
$query->where('name', 'Active');
}])
->with('axleConfiguration')
->findRegNum($request)
->whereNotIn('registration_number', ['AA1460BA', 'AA8227OA', 'AA1916BA', 'AA8312OA', 'AA1918BA'])
->whereRaw("LEFT(registration_number, 6) != 'CHANGE' AND RIGHT(registration_number, 5) != '(OFF)'")
->whereBetween('last_inspection_date', [$fromDate, $toDate])
->orderBy('last_inspection_date', 'asc')
->paginate($request->perPage ?? 10);
return self::successResponse($query, true);
}
错误
{ “error”:“非法运算符和值组合。” }
不应该像下面这样吗?
public function paginated(Request $request)
{
$fromDate = $request->fromDate ? Carbon::parse($request->fromDate) : Carbon::now();
$toDate = $request->toDate ? Carbon::parse($request->toDate) : Carbon::now();
$query = Vehicle::with('class')
->with(['status' => function ($query) {
$query->where('name', 'Active');
}])
->with('axleConfiguration')
->findRegNum($request)
->whereNotIn('registration_number', ['AA1460BA', 'AA8227OA', 'AA1916BA', 'AA8312OA', 'AA1918BA'])
->whereRaw("LEFT(registration_number, 6) != 'CHANGE' AND RIGHT(registration_number, 5) != '(OFF)'")
->whereBetween('last_inspection_date', [$fromDate, $toDate])
->orderBy('last_inspection_date', 'asc')
->paginate($request->perPage ?? 10);
return self::successResponse($query, true);
}
此代码首先使用所有必要的条件和关系构建查询,然后在最后对结果进行分页。