如何在 octobercms 中创建中间件

how to create middleware in octobercms

我是 OctoberCMS 的新手,但我对 Laravel.

有一定了解

在Laravel中很容易创建中间件并将多个中间件分组。

在 OctoberCMS 中,我还找不到合适的指南或满意的答案。

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

在您的插件文件夹中,使用文件 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
     }
}