Completed
Push — master ( 338941...b877df )
by Christopher
01:12
created

BlogServiceProvider::boot()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

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