Filters in Laravel 5

后端 未结 8 989
南笙
南笙 2021-01-31 08:12

How do we make filters in Laravel 5? Is the idea of filters going away?

8条回答
  •  野趣味
    野趣味 (楼主)
    2021-01-31 08:46

    filters.php has been removed and replaced by Kernel.php beside routes.php

    protected $routeMiddleware = [
        'auth' => 'App\Http\Middleware\Authenticate',
        'auth.basic' => 'Illuminate\Auth\Middleware\AuthenticateWithBasicAuth',
        'guest' => 'App\Http\Middleware\RedirectIfAuthenticated',
    ];
    

    But you can't directly add your filter code directly, you should first create a Middleware class (app/Http/Middleware) Then but your desired key in Kernel.php file and reference its own Middleware class, such as:

    'product.check' => 'App\Http\Middleware\ProductChecker'
    

提交回复
热议问题