WhereIn in Eloquent

0

I'm trying to implement a query with the use of whereIn in Eloquent, but it always generates an error,

My code looks like this:

$result = DB::query()->select('permissao')
                     ->whereIn('id_permissoes', $variavel_com_os_valores)
                     ->get();

I have tried to pass the variable inside an array also [$variavel_com_os_valores] , but it always generates error, does anyone know if there is another way to implement a where in ? Even if it is in pure SQL SELECT * FROM tabela WHERE id IN ($variavel) ?

When it does not generate an error message it only returns a return response, that is, it can only verify the first number that is contained in the variable, say that the variable contains 1,2,3 only checks the first number, in the case o 1.

When you generate the error message it is as follows:

  

Warning: Invalid argument supplied for foreach () in   D: \ PROJECTS \ clinicamedica \ vendor \ illuminate \ database \ Query \ Builder.php   online 775

     

Fatal error: Uncaught TypeError: Argument 1 passed to   Illuminate \ Database \ Grammar :: parameterize () must be of the type array,   string given, called in   D: \ PROJECTS \ clinicamedica \ vendor \ illuminate \ database \ Query \ Grammars \ Grammar.php   online 250 and defined in   D: \ PROJECTS \ clinicamedica \ vendor \ illuminate \ database \ Grammar.php: 135   Stack trace: # 0   D: \ PROJECTS \ clinicamedica \ vendor \ illuminate \ database \ Query \ Grammars \ Grammar.php (250):   Illuminate \ Database \ Grammar-> parameterize ('1, 2') # 1   D: \ PROJECTS \ clinicamedica \ vendor \ illuminate \ database \ Query \ Grammars \ Grammar.php (196):   Where (Object (Illuminate \ Database \ Query \ Builder)),   Array) # 2 [internal function]:   Illuminate \ Database \ Query \ Grammars \ Grammar-> Illuminate \ Database \ Query \ Grammars {closure} (Array,   0) # 3   D: \ PROJECTS \ clinicamedica \ vendor \ illuminate \ support \ Collection.php (743):   array_map (Object (Closure), Array, Array) # 4   D: \ PROJECTS \ clinicamedica \ vendor \ illuminate \ database \ Query \ Grammars \ Grammar.php (197):   Illuminate \ Support \ Collection-> (Objec in   D: \ PROJECTS \ clinicamedica \ vendor \ illuminate \ database \ Grammar.php on   line 135 '

    
asked by anonymous 20.07.2017 / 02:17

1 answer

1

According to the documentation of laravel , the "whereIn" method should receive an array as a parameter, even which is just a value.

$result = DB::query()->select( 'permissao' )
                     ->whereIn('id_permissoes', $array )
                     ->get();
    
21.07.2017 / 21:32