0

I am trying to make Laravel Search and stuck at point of handling POST data as an array in Eloquent way

HTML Form is as

<form>
    <select name="hidArray[]">
       <option name="test">Test</option>
       <option name="test2">Test2</option>
    </select>
</form>

Now, this input has been initialized as Bootstrap Multiselect

When i get input as POST request then it has been represented as an array like as below and which is expetced

array:2 [▼
0 => "test"
1 => "test2"
]

Now, i want to form Eloquent query to get results from database.

I tried like as below:

if($request->has('hidArray')){
      $profile->whereIn('hidArray', $request->input('hidArray'));
}

But i think, this way it is not working. Is there any other way i can perform this operation?

w3spi
  • 4,380
  • 9
  • 47
  • 80
Gags
  • 3,759
  • 8
  • 49
  • 96

1 Answers1

1

I don't have exact idea what are you upto but according to what I understood.

You are trying to do something like:

$profile = ModelName::where('user_id',$id);

if($request->has('hidArray')){
      $profile = $profile->whereIn('hidArray', $request->input('hidArray'));
}

$profile = $profile->get();
oreopot
  • 3,392
  • 2
  • 19
  • 28
  • I just want to make sure that the statement that i have written will take care of POST array in WhereIn? – Gags Dec 08 '17 at 17:45
  • 1
    @Gags So try the solution I gave. after all you have to test it on your own. – oreopot Dec 08 '17 at 17:46