<?php

namespace Mehrab\Dashboard\Http\Middleware;

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

class DashboardAdminMiddleware
{
    /**
     * 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(Permission::PERMISSION_AFFILIATE)){
            return redirect()->route('panel.index')->send();
        }
        return $next($request);
    }
}
