Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
93.75% covered (success)
93.75%
15 / 16
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RouteServiceProvider
93.75% covered (success)
93.75%
15 / 16
50.00% covered (danger)
50.00%
1 / 2
3.00
0.00% covered (danger)
0.00%
0 / 1
 boot
100.00% covered (success)
100.00%
13 / 13
100.00% covered (success)
100.00%
1 / 1
1
 configureRateLimiting
66.67% covered (warning)
66.67%
2 / 3
0.00% covered (danger)
0.00%
0 / 1
2.15
1<?php
2
3namespace App\Providers;
4
5use Illuminate\Cache\RateLimiting\Limit;
6use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
7use Illuminate\Http\Request;
8use Illuminate\Support\Facades\RateLimiter;
9use Illuminate\Support\Facades\Route;
10
11class 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 = '/home';
21
22    /**
23     * The controller namespace for the application.
24     *
25     * When present, controller route declarations will automatically be prefixed with this namespace.
26     *
27     * @var string|null
28     */
29    // protected $namespace = 'App\\Http\\Controllers';
30
31    /**
32     * Define your route model bindings, pattern filters, etc.
33     *
34     * @return void
35     */
36    public function boot()
37    {
38        $this->configureRateLimiting();
39
40        $this->routes(function () {
41            Route::prefix('api')
42                ->middleware('api')
43                ->namespace($this->namespace)
44                ->group(base_path('routes/api.php'));
45
46            Route::middleware('web')
47                ->namespace($this->namespace)
48                ->group(base_path('routes/web.php'));
49
50            Route::middleware('web')
51                ->namespace($this->namespace)
52                ->group(base_path('routes/admin.php'));
53        });
54    }
55
56    /**
57     * Configure the rate limiters for the application.
58     *
59     * @return void
60     */
61    protected function configureRateLimiting()
62    {
63        RateLimiter::for('api', function (Request $request) {
64            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
65        });
66    }
67}