Route::group(['middleware' => ['web']], function(){
}
I have a middleware need to get user's point when everytime page load.
Is anyway to let this middleware run without add route group inside of route?
In your App\\Http\\Kernel.php
file, add your middleware in $middleware
array as:
/**
* The application's global HTTP middleware stack.
*
* These middleware are run during every request to your application.
*
* @var array
*/
protected $middleware = [
\Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,
\Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,
\App\Http\Middleware\TrimStrings::class,
\Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,
\App\Http\Middleware\AppAfterMiddleware::class,
];
You can add your middleware in the app/Http/Kernel.php
If you add it to the property protected $middleware
it will run for every request.
Instead added to the proterty protected $middlewareGroups
it will run only for web or api requests.
The code in Kernel.php is commented and pretty self explanatory.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.