Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
92.31% covered (success)
92.31%
12 / 13
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
RouteServiceProvider
92.31% covered (success)
92.31%
12 / 13
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%
10 / 10
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     * Define your route model bindings, pattern filters, etc.
24     *
25     * @return void
26     */
27    public function boot(): void
28    {
29        $this->configureRateLimiting();
30        $this->routes(function () {
31            Route::prefix('api')
32                ->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(): void
48    {
49        RateLimiter::for('api', function (Request $request) {
50            return Limit::perMinute(60)->by(optional($request->user())->id ?: $request->ip());
51        });
52    }
53}