EloquentPageRepository::findHomepage()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php namespace Modules\Page\Repositories\Eloquent;
2
3
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository;
4
use Modules\Page\Events\PageWasCreated;
5
use Modules\Page\Events\PageWasUpdated;
6
use Modules\Page\Repositories\PageRepository;
7
8
class EloquentPageRepository extends EloquentBaseRepository implements PageRepository
9
{
10
    /**
11
     * Find the page set as homepage
12
     * @return object
13
     */
14
    public function findHomepage()
15
    {
16
        return $this->model->where('is_home', 1)->first();
17
    }
18
19
    /**
20
     * Count all records
21
     * @return int
22
     */
23
    public function countAll()
24
    {
25
        return $this->model->count();
26
    }
27
28
    /**
29
     * @param  mixed  $data
30
     * @return object
31
     */
32
    public function create($data)
33
    {
34
        $page = $this->model->create($data);
35
36
        event(new PageWasCreated($page->id, $data));
37
38
        return $page;
39
    }
40
41
    /**
42
     * @param $model
43
     * @param  array  $data
44
     * @return object
45
     */
46
    public function update($model, $data)
47
    {
48
        $model->update($data);
49
50
        event(new PageWasUpdated($model->id, $data));
51
52
        return $model;
53
    }
54
}
55