I make a query as below
$lessonIDs = DB::table($personType."_has_lesson")->where("id",$userID)->pluck("lesson_id");
$lessons = DB::table("lesson")->where("lesson_id",$lessonIDs)->get();
value of lessonIDs
is ["EEZ401","EEZ02","EEZ403"]
I know we can make query with array on Laravel but it returns SQLSTATE[HY093]: Invalid parameter number: parameter was not defined (SQL: select * from "lesson" where "lesson_id" = EEZ401)
. I made some research and I found that is a bug on laravel then I updated the project by composer update
but nothing changed.
- Database is postgresql
- Laravel version is 9.10.1
CodePudding user response:
Where condition doesn't supports Arrays than you have to use WhereIn condition
$lessonIDs = DB::table($personType."_has_lesson")->where("id",$userID)->pluck("lesson_id");
$lessons = DB::table("lesson")->whereIn("lesson_id",$lessonIDs)->get();