Skip to content

Commit f18ec91

Browse files
committed
apply rebase from main
1 parent 76a4f4b commit f18ec91

File tree

6 files changed

+1544
-99
lines changed

6 files changed

+1544
-99
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
}

0 commit comments

Comments
 (0)