Are you working on your package and want to use middleware? Then this is the tutorial for you. In this article is discussed the creation, exposing and testing of middleware in your laravel packages.
Sadly there is no "php artisan make:middleware" in your package environment so you can use them code block below to copy in to your name.
<?php
namespace App\Http\Middleware;
use Closure;
class YourMiddleware
{
public function handle($request, Closure $next)
{
// Perform action
return $next($request);
}
}
There are multiple ways a
Specific route
If you want to make your newly created middleware available as a group, for example when you have multiple middleware that interact with each other than you can add the following code in your package service provider.
public function boot(Router $router) {
$this->loadRoutesFrom(DIR.'/routes.php');
$router->middlewareGroup('admin', [
YOUR_MIDDLEWARE::class,
]);
}
##