<?php
 namespace App\Http\Middleware; use App\Services\License\LicenseService; use Closure; use Illuminate\Http\Request; class EnforceLicense { public function handle(Request $request, Closure $next) { $state = app(LicenseService::class)->state(); view()->share('licenseNotice', in_array($state['state'], ['grace', 'unlicensed', 'invalid'], true) ? $state : null); if ($state['degrade']) { $routeName = (string) (optional($request->route())->getName() ?? ''); foreach ((array) config('license.blocked_route_prefixes_when_invalid', []) as $prefix) { if ($routeName !== '' && str_starts_with($routeName, $prefix)) { $msg = $state['message'] ?: 'Lisansınız geçersiz — yeni işlem yapılamıyor.'; if ($request->expectsJson()) { return response()->json(['message' => $msg, 'license' => 'invalid'], 403); } return redirect()->back()->with('error', $msg); } } } return $next($request); } } 