PostsController::archive()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 0
cts 5
cp 0
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
crap 2
1
<?php namespace Arcanesoft\Blog\Http\Controllers\Front;
2
3
use Arcanesoft\Blog\Models\Post;
4
5
/**
6
 * Class     PostsController
7
 *
8
 * @package  Arcanesoft\Blog\Http\Controllers\Front
9
 * @author   ARCANEDEV <[email protected]>
10
 *
11
 * @todo: Complete the seo feature.
12
 */
13
class PostsController extends Controller
14
{
15
    /* -----------------------------------------------------------------
16
     |  Main Methods
17
     | -----------------------------------------------------------------
18
     */
19
20
    public function index()
21
    {
22
        $posts = Post::published()->latest()->paginate(6);
23
24
        return $this->view('blog::front.posts.index', compact('posts'));
25
    }
26
27
    public function show($slug)
28
    {
29
        /** @var  \Arcanesoft\Blog\Models\Post  $post */
30
        $post = Post::published()->where('slug', $slug)->firstOrFail();
31
32
        $this->setTitle($post->seo->title);
33
        $this->setDescription($post->seo->description);
34
        $this->setKeywords($post->seo->keywords ? $post->seo->keywords->toArray() : []);
35
        $this->addBreadcrumb($post->title);
36
37
        return $this->view('blog::front.posts.single', compact('post'));
38
    }
39
40
    public function archive($year)
41
    {
42
        $posts = Post::publishedAt($year)->latest()->paginate(6);
43
44
        return $this->view('blog::front.posts.single', compact('posts'));
45
    }
46
}
47