Passed
Push — main ( 8a25dd...3c103b )
by TARIQ
12:48
created

RouteServiceProvider   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 39
c 0
b 0
f 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 11 1
A configureRateLimiting() 0 4 2
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 = '/home';
21
22
    /**
23
     * Define your route model bindings, pattern filters, and other route configuration.
24
     *
25
     * @return void
26
     */
27
    public function boot()
28
    {
29
        $this->configureRateLimiting();
30
31
        $this->routes(function () {
32
            Route::middleware('api')
33
                ->prefix('api')
34
                ->group(base_path('routes/api.php'));
0 ignored issues
show
Bug introduced by
The function base_path was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

34
                ->group(/** @scrutinizer ignore-call */ base_path('routes/api.php'));
Loading history...
35
36
            Route::middleware('web')
37
                ->group(base_path('routes/web.php'));
38
        });
39
    }
40
41
    /**
42
     * Configure the rate limiters for the application.
43
     *
44
     * @return void
45
     */
46
    protected function configureRateLimiting()
47
    {
48
        RateLimiter::for('api', function (Request $request) {
49
            return Limit::perMinute(60)->by($request->user()?->id ?: $request->ip());
50
        });
51
    }
52
}
53