Select query for retrieve checkbox data in laravel

Greeting developers, I am new to laravel.I try to create checkbox form and try to retrieve data from it. It works for me but is there any easiest method there to do checkbox selection query. I think may be can use array to fetch the particular word but i dont know how the syntax will been in laravel. Below i attach the code thank in advance.

Controller

  public function show()
    {
       $users = DB::table('notification')->whereIn('to', ['member','Merchant,member', 'Affliate,Merchant,member','Affliate,member'])->get();

        return view('usernotify',['users'=>$users]); 
    }

HTML FORM

<div class="tab"><div class="td">
  <label style="bottom: 20px; font-size: 40px;">Notification:  </label><br>
  <label>Content:</label>&nbsp&nbsp<input type="text" name="content" placeholder="content" style="width: 890px;">
  {{csrf_field()}}
   <br>
   <label>To:</label><br><input type="checkbox" name="to[]" value="Affliate">Affiliate<br>
   <input type="checkbox" name="to[]" value="Merchant">Merchant<br>
   <input type="checkbox" name="to[]" value="member">Member<br>
   <input type="submit" value="submit"></div></div>
</form>

1 answer

  • answered 2018-11-08 07:57 Mou Hsiao

    $users = DB::table('notification')->where('to', 'like', '%member%')->get();