you could add a query string to the url.
like mysite.com/form?limit=25 and perform checks in the controller for that input. $request->get('limit');
Hi,
I have a form on a view page that I would like to have control over the number of items that are returned by the paginator. What is the best way to achieve this?
For this example I have two controllers and related Eloquent models for Clients and News. Each client can only have their own news articles returned.
At the moment, I am storing the number of pagination items in the database, which is fine if we are setting each client's properties on the backend . However, what if we want to allow users control over how many articles they can view per page and let users return a large number of records, or filter the query based upon a set of drop-down parameters?
Current setup:
NewsController.php:
public function show($client, $news)
{
$articles = Client::find($client->id)->news()->paginate($client->pagination_items);
return view('news.show', compact('news', 'client', 'articles'));
}
news\show.blade.php:
@foreach ($articles as $article)
<h2>{{ $article->title }}</h2>
<p>{{ $article->body }}</p>
@endforeach
What i'd ideally like to incorporate on the view is something like the control below, which would allow users to select their own number of articles to display per page, without it being saved to the database:
{!! Form::select('pagination_items', array('20' => '20', '25' => '25', '50' => '50') !!}
Please or to participate in this conversation.