如何在octobercms中创建中间件

时间:2016-11-23 12:14:05

标签: php laravel authentication middleware octobercms

我是 OctoberCMS 的新手,但我对 Laravel 有一定的了解。

在Laravel中,很容易创建中间件并组合多个中间件。

10月份,我无法找到合适的指导方针或令人满意的答案。

有谁知道如何创建中间件并在OctoberCMS中分组多个中间件?

1 个答案:

答案 0 :(得分:5)

在插件文件夹中,使用Plugin.php文件设置中间件 您必须在启动函数中声明如下:

  public function boot()
  {
    // Register middleware
     $this->app['Illuminate\Contracts\Http\Kernel']
          ->pushMiddleware('Experty\Experts\Middleware\ExpertsMiddleware');
  }

和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
     }
}