Answer the question
In order to leave comments, you need to log in
How to make a whereIn selection on two arrays?
I am writing a platform on laravel 5.5.
There are two arrays, one is stored in the database, the second we pass to the request via ORM.
Both arrays are one-dimensional, of the form [0, 5, 87]
The first array must be passed to the query to compare with the array from the database .
At least one of the values must match for the selection
How to do this correctly? At
$query->where('permission_group', '?|', [0, 5])->get()
SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "$2"
LINE 1: ...m "forms" where "archive" = $1 and "permission_group" $2| $3
^ (SQL: select "form_id", "form_category_id", "form_name", "sequence_order", "permission_group" from "forms" where "archive" = 0 and "permission_group" 0| 5)
Answer the question
In order to leave comments, you need to log in
whereIn is right in the question, why is it not in the code?
and what is this anyway?
Eloquent has a whereIn method, in which you pass the field by which you are comparing as the first parameter, and the array by which you make the selection is passed to the second parameter.
Example:
Here you will get from the database only those records in which the id corresponds to the numbers listed in the array passed in the second parameter.
Or do you want to make a selection using the array field type in the database functionality of the database? What database is mysql?
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question