create new middlware and add in route and kernel

This commit is contained in:
2025-04-22 13:45:04 +03:30
parent 1da6414256
commit aef3bfdd94
4 changed files with 38 additions and 27 deletions

View File

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