|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace Yajra\CMS\Presenters; |
|
4
|
|
|
|
|
5
|
|
|
use Laracasts\Presenter\Presenter; |
|
6
|
|
|
|
|
7
|
|
|
class ArticlePresenter extends Presenter |
|
8
|
|
|
{ |
|
9
|
|
|
/** |
|
10
|
|
|
* Edit link of the article. |
|
11
|
|
|
* |
|
12
|
|
|
* @return string |
|
13
|
|
|
*/ |
|
14
|
|
|
public function editLink() |
|
15
|
|
|
{ |
|
16
|
|
|
return html()->linkRoute('administrator.articles.edit', $this->entity->title, $this->entity->id); |
|
17
|
|
|
} |
|
18
|
|
|
|
|
19
|
|
|
/** |
|
20
|
|
|
* Date created. |
|
21
|
|
|
* |
|
22
|
|
|
* @return string |
|
23
|
|
|
*/ |
|
24
|
|
|
public function dateCreated() |
|
25
|
|
|
{ |
|
26
|
|
|
return $this->entity->created_at->format('Y-m-d'); |
|
27
|
|
|
} |
|
28
|
|
|
|
|
29
|
|
|
/** |
|
30
|
|
|
* Date published. |
|
31
|
|
|
* |
|
32
|
|
|
* @return mixed |
|
33
|
|
|
*/ |
|
34
|
|
|
public function datePublished() |
|
35
|
|
|
{ |
|
36
|
|
|
return $this->entity->created_at->format('d M Y'); |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Date modified. |
|
41
|
|
|
* |
|
42
|
|
|
* @return mixed |
|
43
|
|
|
*/ |
|
44
|
|
|
public function dateModified() |
|
45
|
|
|
{ |
|
46
|
|
|
return $this->entity->updated_at->format('d M Y'); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
|
|
/** |
|
50
|
|
|
* Publication state. |
|
51
|
|
|
* |
|
52
|
|
|
* @return string |
|
53
|
|
|
*/ |
|
54
|
|
|
public function published() |
|
55
|
|
|
{ |
|
56
|
|
|
$class = $this->entity->published ? 'fa fa-check-circle-o' : 'fa fa-circle-o'; |
|
57
|
|
|
$state = $this->entity->published ? 'Published' : 'Unpublished'; |
|
58
|
|
|
|
|
59
|
|
|
return html()->tag('i', '', ["class" => $class, "data-toggle" => "tooltip", "data-title" => $state]); |
|
60
|
|
|
} |
|
61
|
|
|
|
|
62
|
|
|
/** |
|
63
|
|
|
* Get article's author name. |
|
64
|
|
|
* |
|
65
|
|
|
* @return string |
|
66
|
|
|
*/ |
|
67
|
|
|
public function author() |
|
68
|
|
|
{ |
|
69
|
|
|
return ! empty($this->entity->author_alias) |
|
70
|
|
|
? $this->entity->author_alias |
|
71
|
|
|
: $this->entity->createdByName; |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* Get the article's content. |
|
76
|
|
|
* |
|
77
|
|
|
* @return string |
|
78
|
|
|
* @throws \Exception |
|
79
|
|
|
* @throws \Throwable |
|
80
|
|
|
*/ |
|
81
|
|
|
public function content() |
|
82
|
|
|
{ |
|
83
|
|
|
return $this->entity->blade_template |
|
84
|
|
|
? view($this->entity->blade_template, compact('article', $this->entity))->render() |
|
|
|
|
|
|
85
|
|
|
: $this->entity->body; |
|
86
|
|
|
} |
|
87
|
|
|
|
|
88
|
|
|
/** |
|
89
|
|
|
* Get the article's title. |
|
90
|
|
|
* |
|
91
|
|
|
* @return mixed |
|
92
|
|
|
*/ |
|
93
|
|
|
public function title() |
|
94
|
|
|
{ |
|
95
|
|
|
$heading = null; |
|
96
|
|
|
if (session()->has('active_menu')) { |
|
97
|
|
|
$heading = session('active_menu')->param('page_heading'); |
|
98
|
|
|
} |
|
99
|
|
|
|
|
100
|
|
|
return $heading ? $heading : $this->entity->title; |
|
101
|
|
|
} |
|
102
|
|
|
|
|
103
|
|
|
/** |
|
104
|
|
|
* Get article's slug. |
|
105
|
|
|
* |
|
106
|
|
|
* @return string |
|
107
|
|
|
*/ |
|
108
|
|
|
public function slug() |
|
109
|
|
|
{ |
|
110
|
|
|
return implode('/', explode('.', $this->entity->getRouteName())); |
|
111
|
|
|
} |
|
112
|
|
|
} |
|
113
|
|
|
|
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: