I'm new to OctoberCMS but I have moderate knowledge about Laravel.
In Laravel it is easy to create middleware and group more than one middleware.
In OctoberCMS I can't find proper guidelines or a satisfactory answer yet.
Does anyone know how to create middleware and group more then one middleware in OctoberCMS ?
In your plugin folder, use the file Plugin.php to set up your middleware You must declare in boot function like this :
public function boot()
{
// Register middleware
$this->app['Illuminate\Contracts\Http\Kernel']
->pushMiddleware('Experty\Experts\Middleware\ExpertsMiddleware');
}
and in ExpertsMiddleware.php
<?php namespace Experty\Experts\Middleware;
use Closure;
use Illuminate\Foundation\Application;
use Illuminate\Contracts\Routing\Middleware;
use Illuminate\Http\Response;
use October\Rain\Exception\AjaxException;
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
class ExpertsMiddleware implements Middleware
{
/**
* The Laravel Application
*
* @var Application
*/
protected $app;
/**
* Create a new middleware instance.
*
* @param Application $app
* @return void
*/
public function __construct(Application $app)
{
$this->app = $app;
}
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
//youre code
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With