|
1
|
|
|
<?php namespace Modules\Page\Repositories\Eloquent; |
|
2
|
|
|
|
|
3
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
4
|
|
|
use Modules\Core\Repositories\Eloquent\EloquentBaseRepository; |
|
5
|
|
|
use Modules\Page\Events\PageWasCreated; |
|
6
|
|
|
use Modules\Page\Events\PageWasUpdated; |
|
7
|
|
|
use Modules\Page\Repositories\PageRepository; |
|
8
|
|
|
|
|
9
|
|
|
class EloquentPageRepository extends EloquentBaseRepository implements PageRepository |
|
10
|
|
|
{ |
|
11
|
|
|
/** |
|
12
|
|
|
* Find the page set as homepage |
|
13
|
|
|
* @return object |
|
14
|
|
|
*/ |
|
15
|
|
|
public function findHomepage() |
|
16
|
|
|
{ |
|
17
|
|
|
return $this->model->where('is_home', 1)->first(); |
|
18
|
|
|
} |
|
19
|
|
|
|
|
20
|
|
|
/** |
|
21
|
|
|
* Count all records |
|
22
|
|
|
* @return int |
|
23
|
|
|
*/ |
|
24
|
|
|
public function countAll() |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->model->count(); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* @param mixed $data |
|
31
|
|
|
* @return object |
|
32
|
|
|
*/ |
|
33
|
|
|
public function create($data) |
|
34
|
|
|
{ |
|
35
|
|
|
$page = $this->model->create($data); |
|
36
|
|
|
|
|
37
|
|
|
event(new PageWasCreated($page->id, $data)); |
|
38
|
|
|
|
|
39
|
|
|
return $page; |
|
40
|
|
|
} |
|
41
|
|
|
|
|
42
|
|
|
/** |
|
43
|
|
|
* @param $model |
|
44
|
|
|
* @param array $data |
|
45
|
|
|
* @return object |
|
46
|
|
|
*/ |
|
47
|
|
|
public function update($model, $data) |
|
48
|
|
|
{ |
|
49
|
|
|
$model->update($data); |
|
50
|
|
|
|
|
51
|
|
|
event(new PageWasUpdated($model->id, $data)); |
|
52
|
|
|
|
|
53
|
|
|
return $model; |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
/** |
|
57
|
|
|
* @param $slug |
|
58
|
|
|
* @param $locale |
|
59
|
|
|
* @return object |
|
60
|
|
|
*/ |
|
61
|
|
|
public function findBySlugInLocale($slug, $locale) |
|
62
|
|
|
{ |
|
63
|
|
|
if (method_exists($this->model, 'translations')) { |
|
64
|
|
|
return $this->model->whereHas('translations', function (Builder $q) use ($slug, $locale) { |
|
65
|
|
|
$q->where('slug', $slug); |
|
66
|
|
|
$q->where('locale', $locale); |
|
67
|
|
|
})->with('translations')->first(); |
|
68
|
|
|
} |
|
69
|
|
|
|
|
70
|
|
|
return $this->model->where('slug', $slug)->where('locale', $locale)->first(); |
|
71
|
|
|
} |
|
72
|
|
|
} |
|
73
|
|
|
|