RouteServiceProvider::configureRateLimiting()   A
last analyzed

Complexity

Conditions 2
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

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
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 controller namespace for the application.
15
     *
16
     * When present, controller route declarations will automatically be prefixed with this namespace.
17
     *
18
     * @var string|null
19
     */
20
    // protected $namespace = 'App\\Http\\Controllers';
21
22
    /**
23
     * Define your route model bindings, pattern filters, etc.
24
     *
25
     * @return void
26
     */
27
    public function boot()
28
    {
29
        $this->configureRateLimiting();
30
31
        //$this->routes(function () {
32
            //Route::middleware('api')
33
            //    ->namespace($this->namespace)
34
            //    ->group(base_path('routes/api.php'));
35
36
            //Route::middleware('web')
37
            //    ->namespace($this->namespace)
38
            //    ->group(base_path('routes/web.php'));
39
        //});
40
    }
41
42
    /**
43
     * Configure the rate limiters for the application.
44
     *
45
     * @return void
46
     */
47
    protected function configureRateLimiting()
48
    {
49
        RateLimiter::for('api', function (Request $request) {
50
            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
51
        });
52
    }
53
}
54