Monday, May 22, 2017

Laravel 5.2 - Paginator appending checkbox array?

Is it possible to append a checkbox array to the paginator? for example I have the following form:

<form method="GET" action="/search" >

   <input type="checkbox" name="foo[]" value="bar1" >
   <input type="checkbox" name="foo[]" value="bar2" >
   <input type="checkbox" name="foo[]" value="bar3" >

   <input type="submit" value="submit">
</form>

 @foreach($users as $user)
    //list users
 @endforeach



And a controller action as follows:

public function search(Request $request)
{

    $foo = $request->input('foo');

    // Get all users where they have foo
    $users = $this->userRepository->getByFilters($foo)->paginate(10); 

    return view('search', compact('users', 'foo');
}

If bar1 and bar2 are selected the Paginator links should generate:

/search?foo[]=bar1&foo[]=bar2

Or should I be passing form array values in url for paginator links some other way i.e. exploding or imploding the foo array?

Any advice appreciated.



via adam78

Advertisement