2019-05-09 15:00:05 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
|
2022-03-24 14:58:28 +01:00
|
|
|
use App\Models\Media;
|
2022-04-01 10:18:04 +02:00
|
|
|
use App\Models\Panier;
|
2022-04-19 14:49:09 +02:00
|
|
|
use Illuminate\Cache\RateLimiting\Limit;
|
2019-05-09 15:00:05 +02:00
|
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
2022-04-19 14:49:09 +02:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
use Illuminate\Support\Facades\RateLimiter;
|
2022-04-19 10:49:38 +02:00
|
|
|
use Illuminate\Support\Facades\Route;
|
2019-05-09 15:00:05 +02:00
|
|
|
|
|
|
|
|
class RouteServiceProvider extends ServiceProvider
|
|
|
|
|
{
|
2022-04-19 10:49:38 +02:00
|
|
|
/**
|
|
|
|
|
* The path to the "home" route for your application.
|
|
|
|
|
*
|
|
|
|
|
* This is used by Laravel authentication to redirect users after login.
|
|
|
|
|
*
|
|
|
|
|
* @var string
|
|
|
|
|
*/
|
|
|
|
|
public const HOME = '/';
|
|
|
|
|
|
2019-05-09 15:00:05 +02:00
|
|
|
/**
|
|
|
|
|
* Define your route model bindings, pattern filters, etc.
|
|
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
|
|
|
|
public function boot()
|
|
|
|
|
{
|
2022-04-19 14:49:09 +02:00
|
|
|
$this->configureRateLimiting();
|
|
|
|
|
|
|
|
|
|
$this->routes(function () {
|
|
|
|
|
Route::middleware('web')
|
|
|
|
|
->group(base_path('routes/web.php'));
|
|
|
|
|
|
2022-04-20 15:23:31 +02:00
|
|
|
Route::middleware('api')
|
|
|
|
|
->prefix('api')
|
2022-04-19 14:49:09 +02:00
|
|
|
->group(base_path('routes/api.php'));
|
|
|
|
|
});
|
|
|
|
|
|
2022-03-24 14:58:28 +01:00
|
|
|
Route::bind('media', function ($value) {
|
|
|
|
|
return Media::whereUid($value)->firstOrFail();
|
|
|
|
|
});
|
2022-04-01 10:18:04 +02:00
|
|
|
Route::bind('basket_uuid', function ($value) {
|
|
|
|
|
return Panier::where('uid', $value)
|
|
|
|
|
->with('owner')->firstOrFail();
|
|
|
|
|
});
|
2019-05-09 15:00:05 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
2022-04-19 14:49:09 +02:00
|
|
|
* Configure the rate limiters for the application.
|
2019-05-09 15:00:05 +02:00
|
|
|
*
|
|
|
|
|
* @return void
|
|
|
|
|
*/
|
2022-04-19 14:49:09 +02:00
|
|
|
protected function configureRateLimiting()
|
2019-05-09 15:00:05 +02:00
|
|
|
{
|
2022-04-19 14:49:09 +02:00
|
|
|
RateLimiter::for('api', function (Request $request) {
|
2022-04-20 15:23:31 +02:00
|
|
|
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
|
2022-04-19 14:49:09 +02:00
|
|
|
});
|
2019-05-09 15:00:05 +02:00
|
|
|
}
|
|
|
|
|
}
|