Illuminate\Routing\Router::pushMiddlewareToGroup PHP Method

pushMiddlewareToGroup() public method

If the middleware is already in the group, it will not be added again.
public pushMiddlewareToGroup ( string $group, string $middleware )
$group string
$middleware string
    public function pushMiddlewareToGroup($group, $middleware)
    {
        if (isset($this->middlewareGroups[$group]) && !in_array($middleware, $this->middlewareGroups[$group])) {
            $this->middlewareGroups[$group][] = $middleware;
        }
        return $this;
    }

Usage Example

 /**
  * Perform post-registration booting of services.
  *
  * @return void
  */
 public function boot(Router $router)
 {
     // load package routes
     if (!$this->app->routesAreCached()) {
         require __DIR__ . '/../../routes.php';
     }
     // make config file available if needed
     $this->publishes([__DIR__ . '/../../config/liveorletdie.php' => config_path('liveorletdie.php')]);
     // register package middleware
     $router->pushMiddlewareToGroup('web', \PeterColes\LiveOrLetDie\Middleware\SessionTimeout::class);
 }
All Usage Examples Of Illuminate\Routing\Router::pushMiddlewareToGroup