2017-11-03 05:26:07 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Providers;
|
|
|
|
|
2021-06-28 01:06:44 +00:00
|
|
|
use Illuminate\Cache\RateLimiting\Limit;
|
2017-11-03 05:26:07 +00:00
|
|
|
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
|
2021-06-28 01:06:44 +00:00
|
|
|
use Illuminate\Http\Request;
|
|
|
|
use Illuminate\Support\Facades\RateLimiter;
|
2020-01-21 10:06:09 +00:00
|
|
|
use Illuminate\Support\Facades\Route;
|
2017-11-03 05:26:07 +00:00
|
|
|
|
|
|
|
class RouteServiceProvider extends ServiceProvider
|
|
|
|
{
|
|
|
|
/**
|
2021-06-28 01:06:44 +00:00
|
|
|
* The path to the "home" route for your application.
|
2017-11-03 05:26:07 +00:00
|
|
|
*
|
2021-06-28 01:06:44 +00:00
|
|
|
* This is used by Laravel authentication to redirect users after login.
|
2017-11-03 05:26:07 +00:00
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2021-06-28 01:06:44 +00:00
|
|
|
public const HOME = '/home';
|
2017-11-03 05:26:07 +00:00
|
|
|
|
2020-01-21 10:06:09 +00:00
|
|
|
/**
|
2021-06-28 01:06:44 +00:00
|
|
|
* The controller namespace for the application.
|
2020-01-21 10:06:09 +00:00
|
|
|
*
|
2021-06-28 01:06:44 +00:00
|
|
|
* When present, controller route declarations will automatically be prefixed with this namespace.
|
|
|
|
*
|
|
|
|
* @var string|null
|
2020-01-21 10:06:09 +00:00
|
|
|
*/
|
2021-06-28 01:06:44 +00:00
|
|
|
// protected $namespace = 'App\\Http\\Controllers';
|
2020-01-21 10:06:09 +00:00
|
|
|
|
2017-11-03 05:26:07 +00:00
|
|
|
/**
|
|
|
|
* Define your route model bindings, pattern filters, etc.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function boot()
|
|
|
|
{
|
2021-06-28 01:06:44 +00:00
|
|
|
$this->configureRateLimiting();
|
|
|
|
|
|
|
|
$this->routes(function () {
|
|
|
|
Route::prefix('api')
|
|
|
|
->middleware('api')
|
|
|
|
->namespace($this->namespace)
|
|
|
|
->group(base_path('routes/api.php'));
|
|
|
|
|
|
|
|
Route::middleware('web')
|
|
|
|
->namespace($this->namespace)
|
|
|
|
->group(base_path('routes/web.php'));
|
|
|
|
});
|
2017-11-03 05:26:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2021-06-28 01:06:44 +00:00
|
|
|
* Configure the rate limiters for the application.
|
2018-04-10 11:23:13 +00:00
|
|
|
*
|
2017-11-03 05:26:07 +00:00
|
|
|
* @return void
|
|
|
|
*/
|
2021-06-28 01:06:44 +00:00
|
|
|
protected function configureRateLimiting()
|
2017-11-03 05:26:07 +00:00
|
|
|
{
|
2021-06-28 01:06:44 +00:00
|
|
|
RateLimiter::for('api', function (Request $request) {
|
|
|
|
return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
|
|
|
|
});
|
2017-11-03 05:26:07 +00:00
|
|
|
}
|
|
|
|
}
|