<?php

namespace Mehrab\Front\Http\Middleware;

use Closure;
use Illuminate\Http\Request;
use Mehrab\RolePermission\Models\Permission;
use Mehrab\RolePermission\Models\Role;

class DashboardUserMiddleware
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle(Request $request, Closure $next)
    {
        if (!auth()->user()->hasRole(Role::ROLE_USER) && !auth()->user()->hasPermissionTo(\Mamad\RolePermissions\Models\Permission::PERMISSION_AFFILIATE)){
            return redirect()->route("admin.dashboard")->send();
        }
        return $next($request);
    }
}
