Laravel 8 中的非法运算符和值组合

问题描述 投票:0回答:1

为什么做超过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”:“非法运算符和值组合。” }

php laravel laravel-8
1个回答
0
投票

不应该像下面这样吗?

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);
}

此代码首先使用所有必要的条件和关系构建查询,然后在最后对结果进行分页。

© www.soinside.com 2019 - 2024. All rights reserved.