Current File : /home/tradevaly/text.tradevaly.com.bd/app/Http/Middleware/AdminMidddleWare.php |
<?php
namespace App\Http\Middleware;
use Brian2694\Toastr\Facades\Toastr;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Models\Admin;
use App\Models\RoleHasPermission;
use App\Models\Role;
class AdminMidddleWare
{
public function handle(Request $request, Closure $next,$roles = null, $permissions = null)
{
if(!Auth::guard('admin')->check()){
Toastr::error("Action restricted!");
return redirect('/b2b/admin_login');
}
if(Auth::guard('admin')->check()){
$user = Auth::guard('admin')->user();
$hasRole = $user->role;
$haspermission = RoleHasPermission::where('role_id',$hasRole->id)->where('route_name', $permissions)
->exists();
if ($haspermission && $hasRole) {
return $next($request);
}
}
abort(404);
}
}