RouteServiceProvider::configureRateLimiting()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2.1481

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 2
c 1
b 0
f 0
nc 1
nop 0
dl 0
loc 4
ccs 2
cts 3
cp 0.6667
crap 2.1481
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
     * This is used by Laravel authentication to redirect users after login.
17
     *
18
     * @var string
19
     */
20
    public const HOME = '/dashboard';
21
22
    /**
23
     * {@inheritDoc}
24
     */
25
    // protected $namespace = 'App\\Http\\Controllers';
26
27
    /**
28
     * Define your route model bindings, pattern filters, etc.
29
     *
30
     * @return void
31
     */
32 12
    public function boot()
33
    {
34 12
        $this->configureRateLimiting();
35
36 12
        $this->routes(function () {
37 12
            Route::prefix('api')
38 12
                ->middleware('api')
39 12
                ->namespace($this->namespace)
40 12
                ->group(base_path('routes/api.php'));
41
42 12
            Route::middleware('web')
43 12
                ->namespace($this->namespace)
44 12
                ->group(base_path('routes/web.php'));
45 12
        });
46 12
    }
47
48
    /**
49
     * Configure the rate limiters for the application.
50
     *
51
     * @return void
52
     */
53 12
    protected function configureRateLimiting()
54
    {
55 12
        RateLimiter::for('api', function (Request $request) {
56
            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
57 12
        });
58 12
    }
59
}
60