G
G
GrimJack2017-09-25 17:06:59
PostgreSQL
GrimJack, 2017-09-25 17:06:59

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()

I get an error
spoiler
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)

How to do it right?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Alexander Aksentiev, 2017-09-25
@Sanasol

whereIn is right in the question, why is it not in the code?
and what is this anyway?

A
Alexey Budaev, 2017-09-25
@Markus_Kane

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.

E
Elena Stepanova, 2017-09-26
@Insolita

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 question

Ask a Question

731 491 924 answers to any question