Skip to content

Commit 5476dc8

Browse files
committed
Consolidate service providers
1 parent ac270f6 commit 5476dc8

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

app/Providers/AppServiceProvider.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,22 @@
22

33
namespace App\Providers;
44

5+
use Illuminate\Cache\RateLimiting\Limit;
6+
use Illuminate\Http\Request;
7+
use Illuminate\Support\Facades\RateLimiter;
58
use Illuminate\Support\ServiceProvider;
69

710
class AppServiceProvider extends ServiceProvider
811
{
12+
/**
13+
* The path to your application's "home" route.
14+
*
15+
* Typically, users are redirected here after authentication.
16+
*
17+
* @var string
18+
*/
19+
public const HOME = '/home';
20+
921
/**
1022
* Register any application services.
1123
*/
@@ -20,5 +32,14 @@ public function register(): void
2032
public function boot(): void
2133
{
2234
//
35+
36+
$this->bootRoute();
37+
}
38+
39+
public function bootRoute(): void
40+
{
41+
RateLimiter::for('api', function (Request $request) {
42+
return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
43+
});
2344
}
2445
}

bootstrap/app.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?php
22

3+
use App\Providers\AppServiceProvider;
34
use Illuminate\Foundation\Application;
45
use Illuminate\Foundation\Configuration\Exceptions;
56
use Illuminate\Foundation\Configuration\Middleware;
@@ -15,7 +16,7 @@
1516
)
1617
->withMiddleware(function (Middleware $middleware) {
1718
$middleware->redirectGuestsTo(fn () => route('login'));
18-
$middleware->redirectUsersTo(RouteServiceProvider::HOME);
19+
$middleware->redirectUsersTo(AppServiceProvider::HOME);
1920

2021
$middleware->web(\App\Http\Middleware\DisableFloc::class);
2122

0 commit comments

Comments
 (0)