How to use alias column in whereIn with Laravel?
问题 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