|
1
|
|
|
<?php |
|
2
|
|
|
/** |
|
3
|
|
|
* Created by PhpStorm. |
|
4
|
|
|
* User: Mark |
|
5
|
|
|
* Date: 04/03/2016 |
|
6
|
|
|
* Time: 23:07. |
|
7
|
|
|
*/ |
|
8
|
|
|
|
|
9
|
|
|
namespace App\Classes\Repositories; |
|
10
|
|
|
|
|
11
|
|
|
use App\Model\Page; |
|
12
|
|
|
use Illuminate\Support\Collection; |
|
13
|
|
|
use Illuminate\Database\Eloquent\Builder; |
|
14
|
|
|
|
|
15
|
|
|
/** |
|
16
|
|
|
* Class PageRepository. |
|
17
|
|
|
* |
|
18
|
|
|
* @method Page withTrashed |
|
19
|
|
|
*/ |
|
20
|
|
|
class PageRepository extends BaseRepository |
|
21
|
|
|
{ |
|
22
|
|
|
/** |
|
23
|
|
|
* @var Page|Builder|Collection |
|
24
|
|
|
*/ |
|
25
|
|
|
protected $model; |
|
26
|
|
|
|
|
27
|
|
|
/** |
|
28
|
|
|
* PageRepository constructor. |
|
29
|
|
|
* |
|
30
|
|
|
* @param Page $model |
|
31
|
|
|
*/ |
|
32
|
|
|
public function __construct(Page $model) |
|
33
|
|
|
{ |
|
34
|
|
|
$this->model = $model; |
|
35
|
|
|
} |
|
36
|
|
|
|
|
37
|
|
|
/** |
|
38
|
|
|
* @param $plugin_name |
|
39
|
|
|
* @return mixed |
|
40
|
|
|
*/ |
|
41
|
|
|
public function restoreTrashedPlugin($plugin_name) |
|
42
|
|
|
{ |
|
43
|
|
|
return $this->model->withTrashed()->where('plugin', $plugin_name)->restore(); |
|
44
|
|
|
} |
|
45
|
|
|
|
|
46
|
|
|
/** |
|
47
|
|
|
* @return mixed |
|
48
|
|
|
*/ |
|
49
|
|
|
public function makeList() : array |
|
50
|
|
|
{ |
|
51
|
|
|
return $this->model->pluck('seo_title', 'id')->toArray(); |
|
|
|
|
|
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @deprecated |
|
56
|
|
|
*/ |
|
57
|
|
|
public function listAllPagesWithoutMenusAndEditable() |
|
|
|
|
|
|
58
|
|
|
{ |
|
59
|
|
|
return $this->model->where('editable', true)->doesntHave('menu')->pluck('seo_title', 'id'); |
|
|
|
|
|
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
public function listPagesWithoutMenus() |
|
|
|
|
|
|
63
|
|
|
{ |
|
64
|
|
|
return $this->model->doesntHave('menu')->get(); |
|
|
|
|
|
|
65
|
|
|
} |
|
66
|
|
|
|
|
67
|
|
|
public function allPagesWithoutMenusAndEditable() : Collection |
|
68
|
|
|
{ |
|
69
|
|
|
return $this->model->where('editable', true)->doesntHave('menus')->get(); |
|
|
|
|
|
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
* Get the page based on its name. |
|
74
|
|
|
* |
|
75
|
|
|
* @param $string |
|
76
|
|
|
* @return Page|array|\stdClass |
|
77
|
|
|
*/ |
|
78
|
|
|
public function whereName($string) : Page |
|
79
|
|
|
{ |
|
80
|
|
|
return $this->model->where('slug', $string)->first(); |
|
|
|
|
|
|
81
|
|
|
} |
|
82
|
|
|
|
|
83
|
|
|
/** |
|
84
|
|
|
* @param $string |
|
85
|
|
|
* @return Page |
|
86
|
|
|
*/ |
|
87
|
|
|
public function whereRoute($string) : Page |
|
88
|
|
|
{ |
|
89
|
|
|
return $this->model->where('route', $string)->first(); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
/** |
|
93
|
|
|
* @param $string |
|
94
|
|
|
* @return Page |
|
95
|
|
|
*/ |
|
96
|
|
|
public function wherePlugin($string) : Page |
|
97
|
|
|
{ |
|
98
|
|
|
return $this->model->where('plugin', $string)->first(); |
|
|
|
|
|
|
99
|
|
|
} |
|
100
|
|
|
|
|
101
|
|
|
/** |
|
102
|
|
|
* Sitemap enabled pages. |
|
103
|
|
|
*/ |
|
104
|
|
|
public function whereSitemap() : Collection |
|
105
|
|
|
{ |
|
106
|
|
|
return $this->model->where('sitemap', true)->where('enabled', true)->get(); |
|
|
|
|
|
|
107
|
|
|
} |
|
108
|
|
|
|
|
109
|
|
|
/** |
|
110
|
|
|
* Return all pages that are enabled. |
|
111
|
|
|
*/ |
|
112
|
|
|
public function enabled() : Collection |
|
113
|
|
|
{ |
|
114
|
|
|
return $this->model->where('enabled', true)->get(); |
|
|
|
|
|
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function frontendPageCollection() |
|
|
|
|
|
|
118
|
|
|
{ |
|
119
|
|
|
return $this->model->with(['menu'])->get(); |
|
|
|
|
|
|
120
|
|
|
// return $this->with(['menu' => function ($query) { |
|
|
|
|
|
|
121
|
|
|
// $query->with('parent'); |
|
122
|
|
|
// }])->get(); |
|
123
|
|
|
} |
|
124
|
|
|
} |
|
125
|
|
|
|
It seems like the method you are trying to call exists only in some of the possible types.
Let’s take a look at an example:
Available Fixes
Add an additional type-check:
Only allow a single type to be passed if the variable comes from a parameter: