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