BlogServiceProvider   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 4
dl 0
loc 46
rs 10
c 0
b 0
f 0

3 Methods

Rating   Name   Duplication   Size   Complexity  
A boot() 0 13 1
A map() 0 4 1
A mapBlogRoutes() 0 5 1
1
<?php
2
3
namespace App\Providers;
4
5
use Chriscreates\Blog\Observers\PostObserver;
6
use Chriscreates\Blog\Post;
7
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
8
use Illuminate\Support\Facades\Route;
9
10
class BlogServiceProvider extends ServiceProvider
11
{
12
    protected $namespace = '\Chriscreates\Blog\Controllers';
13
14
    /**
15
     * Define your route model bindings, pattern filters, etc.
16
     *
17
     * @return void
18
     */
19
    public function boot()
20
    {
21
        parent::boot();
22
23
        Route::bind('post', function ($value) {
24
            return Post::where(function ($query) use ($value) {
25
                $query->where('id', $value)
26
                ->orWhere('slug', 'LIKE', "%{$value}%");
27
            })->first();
28
        });
29
30
        Post::observe(PostObserver::class);
31
    }
32
33
    /**
34
     * Define the routes for the application.
35
     *
36
     * @return void
37
     */
38
    public function map()
39
    {
40
        $this->mapBlogRoutes();
41
    }
42
43
    /**
44
     * Define the "api" routes for the application.
45
     *
46
     * These routes are typically stateless.
47
     *
48
     * @return void
49
     */
50
    protected function mapBlogRoutes()
51
    {
52
        Route::namespace($this->namespace)
53
        ->group(base_path('routes/blog.php'));
54
    }
55
}
56