jonnybarnes.uk/app/Providers/RouteServiceProvider.php

49 lines
1.3 KiB
PHP
Raw Normal View History

2016-05-19 15:01:28 +01:00
<?php
namespace App\Providers;
2020-10-17 17:15:06 +01:00
use Illuminate\Cache\RateLimiting\Limit;
2016-05-19 15:01:28 +01:00
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
2020-10-17 17:15:06 +01:00
use Illuminate\Http\Request;
use Illuminate\Support\Facades\RateLimiter;
2019-10-19 15:34:49 +01:00
use Illuminate\Support\Facades\Route;
2016-05-19 15:01:28 +01:00
class RouteServiceProvider extends ServiceProvider
{
/**
2023-02-18 09:34:57 +00:00
* The path to the "home" route for your application.
2016-05-19 15:01:28 +01:00
*
2023-02-18 09:34:57 +00:00
* Typically, users are redirected here after authentication.
2016-05-19 15:01:28 +01:00
*
2023-02-18 09:34:57 +00:00
* @var string
2016-05-19 15:01:28 +01:00
*/
2023-02-18 09:34:57 +00:00
public const HOME = '/admin';
2016-05-19 15:01:28 +01:00
/**
2023-02-18 09:34:57 +00:00
* Define your route model bindings, pattern filters, and other route configuration.
2016-05-19 15:01:28 +01:00
*/
2023-02-18 09:34:57 +00:00
public function boot(): void
2016-05-19 15:01:28 +01:00
{
2020-10-17 17:15:06 +01:00
$this->configureRateLimiting();
$this->routes(function () {
2023-02-18 09:34:57 +00:00
Route::middleware('api')
->prefix('api')
2020-10-17 17:15:06 +01:00
->group(base_path('routes/api.php'));
Route::middleware('web')
->group(base_path('routes/web.php'));
});
2016-05-19 15:01:28 +01:00
}
/**
2020-10-17 17:15:06 +01:00
* Configure the rate limiters for the application.
2016-09-06 16:40:39 +01:00
*/
2023-02-18 09:34:57 +00:00
protected function configureRateLimiting(): void
2016-05-19 15:01:28 +01:00
{
2020-10-17 17:15:06 +01:00
RateLimiter::for('api', function (Request $request) {
2023-02-18 09:34:57 +00:00
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
2020-10-17 17:15:06 +01:00
});
2016-05-19 15:01:28 +01:00
}
}