问题
here is my code. I am trying to get new list of A items in order to loop on.
$allowed_a = \App\NewA::select('name')->get()->pluck('name');
$a = App\A::selectRaw("replace(unaccent(trim(name)), ' ', '') AS newname, name")
->whereIn('newname', $allowed_a)->get();
But I am getting Undefined column 'newname'. How can I fix it please? thanks
回答1:
You should be able to achieve something equivalent using:
$allowed_a = \App\NewA;
\App\A::selectRaw('replace(unaccent(trim(name)) as newname')
->whereRaw('replace(unaccent(trim(name)) IN ("'.implode('","', $allowed_a).'")')
->get()
来源:https://stackoverflow.com/questions/62953660/how-to-use-alias-column-in-wherein-with-laravel