Files
backend/app/Http/Middleware/ValidateShowAccess.php

33 lines
850 B
PHP

<?php
namespace App\Http\Middleware;
use App\Exceptions\ProhibitedAction;
use Closure;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Symfony\Component\HttpFoundation\Response;
use Throwable;
class ValidateShowAccess
{
/**
* Handle an incoming request.
*
* @param Closure(Request): (Response) $next
* @throws Throwable
*/
public function handle(Request $request, Closure $next): Response
{
$user = Auth::user();
throw_if (is_null($user->province_id),
new ProhibitedAction('استانی برای شما در سامانه ثبت نشده است!'));
throw_if(is_null($user->edarate_shahri_id),
new ProhibitedAction('اداره شهری برای شما در سامانه ثبت نشده است!'));
return $next($request);
}
}