Support the ongoing development of Laravel.io →
Authentication Security
Last updated 1 year ago.
0

Laravel already has authorization, and you can use them with middleware. read this https://laravel.com/docs/5.3/authorization#via-middleware

0
class CheckRole
{
    public function handle(Request $request, Closure $next, $role)
    {
        $user = $request->user();

        if (! $user->role == $role) {
            return redirect(...);
        }

        return $next($request);
    }
}

'middleware' => ['hasrole:1']

0

Sign in to participate in this thread!

Eventy

Your banner here too?

matejMurin matejmurin Joined 28 Jul 2016

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.