Lae/app/Providers/RouteServiceProvider.php

64 lines
1.7 KiB
PHP
Raw Normal View History

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