1
votes

I need to create SuperAdmin middleware in my app called 'master' so I make middleware 'IsMaster' :

<?php

namespace App\Http\Middleware;

use Closure;

class IsMaster
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        if (\Auth::user() &&  \Auth::user()->admin == 101) {
            return $next($request);
        }

        return redirect('/auth/logout');
    }
}

so as you can see from the code above if 'admin' field in my 'users' table has value 101 that is MASTER user.

Now I add this to Kernel.php:

protected $routeMiddleware = [
        'auth' => \App\Http\Middleware\Authenticate::class,
        'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,
        'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,
        'admin' => \App\Http\Middleware\IsAdmin::class,
        'master' => \App\Http\Middleware\IsMaster::class,

    ];

now at AdminController.php I use it like:

class AdminController extends Controller
{

    public function __construct() {
        $this->middleware('master', ['except' => ['getMail']]);
    }

...

when I try to login with master user account I got error:

ReflectionException in Container.php line 741: Class master does not exist

enter image description here

What is a problem here? I really dont see what make the issues...

Also I try: php artisan config:clear, php artisan cache:clear ...

1
my class IsAdmin works perfect ...Aleks Per
composer dumpautoload does it work?Ohgodwhy
Yes, that works! THANKS SO MUCH!Aleks Per

1 Answers

1
votes

Just for sake of marking it as answer.

composer dumpautoload