RouteServiceProvider::mapWebRoutes()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 1
cts 1
cp 1
rs 9.4285
cc 1
eloc 4
nc 1
nop 0
crap 1
1
<?php
2
3
namespace App\Providers;
4
5
use App\Link;
6
use Illuminate\Database\Eloquent\ModelNotFoundException;
7
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
8
use Illuminate\Support\Facades\Route;
9
10
class RouteServiceProvider extends ServiceProvider
11
{
12
    /**
13
     * This namespace is applied to your controller routes.
14
     *
15
     * In addition, it is set as the URL generator's root namespace.
16
     *
17
     * @var string
18
     */
19
    protected $namespace = 'App\Http\Controllers';
20
21
    /**
22
     * Define your route model bindings, pattern filters, etc.
23
     *
24
     * @return void
25
     */
26
    public function boot()
27
    {
28 12
        //
29
        Route::bind('linkHash', function ($hash) {
30 12
            try {
31
                return Link::where('hash', $hash)->firstOrFail();
32 12
            } catch (ModelNotFoundException $e) {
33 12
                redirect('/')->send();
34
            }
35
        });
36
37
        parent::boot();
38
    }
39
40 12
    /**
41
     * Define the routes for the application.
42 12
     *
43
     * @return void
44 12
     */
45
    public function map()
46
    {
47 12
        $this->mapApiRoutes();
48
49
        $this->mapWebRoutes();
50
51
        //
52
    }
53
54
    /**
55
     * Define the "web" routes for the application.
56 12
     *
57
     * These routes all receive session state, CSRF protection, etc.
58 12
     *
59 12
     * @return void
60 12
     */
61 12
    protected function mapWebRoutes()
62
    {
63
        Route::middleware('web')
64
            ->namespace($this->namespace)
65
            ->group(base_path('routes/web.php'));
66
    }
67
68
    /**
69
     * Define the "api" routes for the application.
70 12
     *
71
     * These routes are typically stateless.
72 12
     *
73 12
     * @return void
74 12
     */
75 12
    protected function mapApiRoutes()
76 12
    {
77
        Route::prefix('api')
78
            ->middleware('api')
79
            ->namespace($this->namespace)
80
            ->group(base_path('routes/api.php'));
81
    }
82
}
83