Laravel - input request handling for global pagination
So I am creating an api in Laravel and a majority of the calls being made to it are requests for sortable / filterable / paginated data that will be displayed in data tables. I would like to create "something" that checks every request (sounds like middleware maybe??) and rips out the appropriate sorting / filtering / pagination data and stores it ...."somewhere".
My question is what would be that "something" (middleware? trait?) and in implementing it where would be a good place to store said information. Obviously not in a global variable....if it was a trait maybe I would store it in class properties? I am grasping at straws here and just need a point in the right direction.
Answer
If you're using Laravel 5 you can easily setup whole thing in the middleware directory located in app/http/Middleware
. You create new class there, register it in app/Http/Kernel.php
file in $middleware
property and use your newly running middleware however you like.
Super simple example:
<?php
namespace App\Http\Middleware;
use Closure;
class StoreInfo
{
public function handle($request, Closure $next)
{
// Tear your $request apart here and store however you need.
}
}
As usually - it is advised to do composer dump-autoload
after creating new file.
Related Questions
- → "failed to open stream" error when executing "migrate:make"
- → October CMS Plugin Routes.php not registering
- → OctoberCMS Migrate Table
- → OctoberCMS Rain User plugin not working or redirecting
- → October CMS Custom Mail Layout
- → October CMS - How to correctly route
- → October CMS create a multi select Form field
- → October CMS - Conditionally Load a Different Page
- → How to disable assets combining on development in OctoberCMS
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → OctoberCms component: How to display all ID(items) instead of sorting only one ID?
- → In OctoberCMS how do you find the hint path?
- → How to register middlewares in OctoberCMS plugin?