控制器连续问题

I have problems get the options for select with ajax:

"SQLSTATE[42S22]: Column not found: 1054 Unknown column 'full_name' in 'where clause' (SQL: select count(*) as aggregate from drivers where full_name like %% ▶"

public function drivers(Request $request)
    {
        $q = $request->get('q');

        return Driver::select("id", "first_name", "last_name"
                ,DB::raw("CONCAT(first_name,' ',last_name) as full_name"))
            ->where('full_name', 'like', "%$q%")->paginate(null, ['id', 'full_name as text']);
    }

I do not know where is the problem, any possible solution?

Thanks

You cannot use a virtual column or an alias in a where clause. So try this one instead:

public function drivers(Request $request)
{
    $q = $request->get('q');

    return Driver::select("id", "first_name", "last_name",
           DB::raw("CONCAT(first_name,' ',last_name) as full_name"))
           ->having('full_name', 'like', "%$q%")->simplePaginate(10);
}

Why not try it like this

return Driver
    ::select("id", "first_name", "last_name",DB::raw("CONCAT(first_name,' ',last_name) as full_name"))
    ->whereRaw('full_name like %?%', [$q])
    ->paginate(null, ['id', 'full_name as text']);

https://laravel.com/docs/5.8/queries Raw Methods