Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to use roles? #61

Open
altimea opened this issue Nov 24, 2015 · 3 comments
Open

How to use roles? #61

altimea opened this issue Nov 24, 2015 · 3 comments

Comments

@altimea
Copy link

altimea commented Nov 24, 2015

I have an admin account that it works ok, but now I wanted to create another account type so I went to Users -> Roles and created another one and then created a user for that role, but when I try to log in with that user It gives my a redirection problem in the browser.

What am I missing?

Thanks

@Peterabsolon
Copy link

I'm having the same issue. Logging in with a role other than admin results in redirect loop.

@LiangJianle
Copy link

I'm having the same issue..

@LiangJianle
Copy link

I found the soluation .
The problem is the middleware "OnlyAdmin.php",
I haved rewrite the middleware.
Here is my code:

config.php

return [
    'prefix' => 'admin',
    'filter' => [
        'auth' => [
            **App\Http\Middleware\Authenticate::class,**
            **App\Http\Middleware\OnlyAdmin::class,**
        ],
        **'guest' => App\Http\Middleware\RedirectIfAuthenticated::class,**
    ],

OnlyAdmin.php

<?php

namespace App\Http\Middleware;

use Closure;

class OnlyAdmin
{
    /**
     * Handle an incoming request.
     *
     * @param \Illuminate\Http\Request $request
     * @param \Closure                 $next
     *
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        // var_dump($request->user()->is('testadmin'));
        // if (!$request->user()->is('admin')) {
        //     // return response('OnlyAdmin.', 401);
        //     return redirect()->route('admin.login.index');
        // }

        return $next($request);
    }
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants