ome*_*ooq 4 middleware laravel laravel-5
我有一个名为'AdminMiddleware'的中间件,它正在类的构造函数中使用.由于某些原因,虽然正在运行构造函数,但是没有从构造函数中调用中间件.我尝试在adminMiddleware文件上进行模具转储,但似乎只是忽略了这个文件.
namespace App\Http\Controllers\SuperAdmin;
use Illuminate\Http\Request;
use App\Http\Requests;
use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\Auth;
class dashboard extends Controller
{
protected $user;
public function __construct()
{
$this->middleware('admin');
$this->user = Auth::User();
}
//Kernel.php
protected $routeMiddleware = [
'auth' => \App\Http\Middleware\Authenticate::class,
'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
'superadmin' => \App\Http\Middleware\SuperAdminMiddleware::class,
'admin' => \App\Http\Middleware\AdminMiddleware::class,
];
Run Code Online (Sandbox Code Playgroud)
对于某些项目要求,我无法直接在路线上使用中间件.任何帮助表示赞赏,我正在使用laravel 5.1.
您需要做两件事来在控制器中启用中间件:
在App\Http\Kernel.php中的$ routeMiddleware中注册中间件
protected $ routeMiddleware = ['admin'=>'App\Http\Middleware\AdminMiddleware',];
使用中间件的密钥而非类名在控制器中启用中间件:
$这个 - >中间件( '管理员');
| 归档时间: |
|
| 查看次数: |
9772 次 |
| 最近记录: |