%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /home/silvzytp/crm-ind-code/app/Http/Middleware/
Upload File :
Create Path :
Current File : //home/silvzytp/crm-ind-code/app/Http/Middleware/PermissionMiddleware.php

<?php

namespace App\Http\Middleware;

use Closure;
use App\Models\User;
use App\Models\Permission;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Gate;

class PermissionMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure(\Illuminate\Http\Request): (\Illuminate\Http\Response|\Illuminate\Http\RedirectResponse)  $next
     * @return \Illuminate\Http\Response|\Illuminate\Http\RedirectResponse
     */
    public function handle(Request $request, Closure $next)
    {
        if (Auth::check()) {
            $permissions = Permission::all();
            foreach($permissions as $key => $permission){
                Gate::define($permission->slug,function(User $user) use ($permission) {
                    return $user->hasPermission($permission->slug);
                });
            }
        }

        return $next($request);
    }
}

Zerion Mini Shell 1.0