Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to create middleware in octobercms

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 ?

like image 443
Binit Ghetiya Avatar asked Nov 23 '16 12:11

Binit Ghetiya


1 Answers

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
     }
}
like image 156
Taha Azzabi Avatar answered Oct 15 '22 06:10

Taha Azzabi