File tree Expand file tree Collapse file tree 6 files changed +1544
-99
lines changed Expand file tree Collapse file tree 6 files changed +1544
-99
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ declare (strict_types=1 );
4+
5+ namespace App \Providers ;
6+
7+ use App \Models \User ;
8+ use Illuminate \Cache \RateLimiting \Limit ;
9+ use Illuminate \Foundation \Support \Providers \RouteServiceProvider as ServiceProvider ;
10+ use Illuminate \Http \Request ;
11+ use Illuminate \Support \Facades \RateLimiter ;
12+ use Illuminate \Support \Facades \Route ;
13+
14+ final class RouteServiceProvider extends ServiceProvider
15+ {
16+ public const HOME = '/dashboard ' ;
17+
18+ public function boot (): void
19+ {
20+ $ this ->configureRateLimiting ();
21+
22+ $ this ->routeBindings ();
23+
24+ $ this ->routes (function (): void {
25+ Route::middleware ('web ' )
26+ ->namespace ($ this ->namespace )
27+ ->group (base_path ('routes/web.php ' ));
28+ });
29+ }
30+
31+ protected function configureRateLimiting (): void
32+ {
33+ RateLimiter::for (
34+ name: 'api ' ,
35+ callback: fn (Request $ request ): Limit => Limit::perMinute (60 )
36+ ->by (
37+ (string ) (optional ($ request ->user ())->id ?: $ request ->ip ())
38+ )
39+ );
40+ }
41+
42+ protected function routeBindings (): void
43+ {
44+ Route::bind (
45+ key: 'username ' ,
46+ binder: fn (string $ username ): User => User::findByUsername ($ username )
47+ );
48+ }
49+ }
You can’t perform that action at this time.
0 commit comments