init
This commit is contained in:
@@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Providers;
|
||||
|
||||
use App\Support\TenantContext;
|
||||
use Illuminate\Cache\RateLimiting\Limit;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\RateLimiter;
|
||||
use Illuminate\Support\ServiceProvider;
|
||||
|
||||
class AppServiceProvider extends ServiceProvider
|
||||
{
|
||||
public function register(): void
|
||||
{
|
||||
$this->app->singleton(TenantContext::class);
|
||||
}
|
||||
|
||||
public function boot(): void
|
||||
{
|
||||
RateLimiter::for('api', function (Request $request): Limit {
|
||||
$tenantCode = app(TenantContext::class)->get() ?? 'guest';
|
||||
|
||||
return Limit::perMinute(60)->by($tenantCode.'|'.($request->ip() ?? 'unknown'));
|
||||
});
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user