Passed
Push — master ( e86d60...244abe )
by Brian
05:50 queued 02:48
created

RouteServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 7
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 11
ccs 8
cts 8
cp 1
crap 1
rs 10
1
<?php
2
3
namespace App\Providers;
4
5
use Illuminate\Cache\RateLimiting\Limit;
6
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7
use Illuminate\Http\Request;
8
use Illuminate\Support\Facades\RateLimiter;
9
use Illuminate\Support\Facades\Route;
10
11
class RouteServiceProvider extends ServiceProvider
12
{
13
    /**
14
     * The path to the "home" route for your application.
15
     *
16
     * Typically, users are redirected here after authentication.
17
     *
18
     * @var string
19
     */
20
    public const HOME = '/dashboard';
21
22
    /**
23
     * Define your route model bindings, pattern filters, and other route configuration.
24
     */
25 26
    public function boot(): void
26
    {
27 26
        $this->configureRateLimiting();
28
29 26
        $this->routes(function () {
30 26
            Route::middleware('api')
31 26
                ->prefix('api')
32 26
                ->group(base_path('routes/api.php'));
33
34 26
            Route::middleware('web')
35 26
                ->group(base_path('routes/web.php'));
36 26
        });
37
    }
38
39
    /**
40
     * Configure the rate limiters for the application.
41
     */
42 26
    protected function configureRateLimiting(): void
43
    {
44 26
        RateLimiter::for('api', function (Request $request) {
45
            return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
46 26
        });
47
    }
48
}
49