1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backpack\PageManager\app\Models; |
4
|
|
|
|
5
|
|
|
use Illuminate\Database\Eloquent\Model; |
6
|
|
|
use Backpack\CRUD\CrudTrait; |
7
|
|
|
use Cviebrock\EloquentSluggable\Sluggable; |
8
|
|
|
|
9
|
|
|
class Page extends Model |
10
|
|
|
{ |
11
|
|
|
use CrudTrait; |
12
|
|
|
use Sluggable; |
13
|
|
|
|
14
|
|
|
/* |
15
|
|
|
|-------------------------------------------------------------------------- |
16
|
|
|
| GLOBAL VARIABLES |
17
|
|
|
|-------------------------------------------------------------------------- |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
protected $table = 'pages'; |
21
|
|
|
protected $primaryKey = 'id'; |
22
|
|
|
public $timestamps = true; |
23
|
|
|
// protected $guarded = ['id']; |
|
|
|
|
24
|
|
|
protected $fillable = ['template', 'name', 'title', 'slug', 'content', 'extras']; |
25
|
|
|
// protected $hidden = []; |
|
|
|
|
26
|
|
|
// protected $dates = []; |
|
|
|
|
27
|
|
|
protected $fakeColumns = ['extras']; |
28
|
|
|
|
29
|
|
|
/** |
30
|
|
|
* Return the sluggable configuration array for this model. |
31
|
|
|
* |
32
|
|
|
* @return array |
|
|
|
|
33
|
|
|
*/ |
34
|
|
|
public function sluggable() |
35
|
|
|
{ |
36
|
|
|
return [ |
37
|
|
|
'slug' => [ |
38
|
|
|
'source' => 'slug_or_title', |
39
|
|
|
], |
40
|
|
|
]; |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/* |
44
|
|
|
|-------------------------------------------------------------------------- |
45
|
|
|
| FUNCTIONS |
46
|
|
|
|-------------------------------------------------------------------------- |
47
|
|
|
*/ |
48
|
|
|
|
49
|
|
|
public function getTemplateName() |
50
|
|
|
{ |
51
|
|
|
return trim(preg_replace('/(id|at|\[\])$/i', '', ucfirst(str_replace('_', ' ', $this->template)))); |
|
|
|
|
52
|
|
|
} |
53
|
|
|
|
54
|
|
|
public function getPageLink() |
55
|
|
|
{ |
56
|
|
|
return url($this->slug); |
|
|
|
|
57
|
|
|
} |
58
|
|
|
|
59
|
|
|
public function getOpenButton() |
60
|
|
|
{ |
61
|
|
|
return '<a class="btn btn-default btn-xs" href="'.$this->getPageLink().'" target="_blank"><i class="fa fa-eye"></i> Open</a>'; |
|
|
|
|
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/* |
65
|
|
|
|-------------------------------------------------------------------------- |
66
|
|
|
| RELATIONS |
67
|
|
|
|-------------------------------------------------------------------------- |
68
|
|
|
*/ |
69
|
|
|
|
70
|
|
|
/* |
71
|
|
|
|-------------------------------------------------------------------------- |
72
|
|
|
| SCOPES |
73
|
|
|
|-------------------------------------------------------------------------- |
74
|
|
|
*/ |
75
|
|
|
|
76
|
|
|
/* |
77
|
|
|
|-------------------------------------------------------------------------- |
78
|
|
|
| ACCESORS |
79
|
|
|
|-------------------------------------------------------------------------- |
80
|
|
|
*/ |
81
|
|
|
|
82
|
|
|
// The slug is created automatically from the "name" field if no slug exists. |
83
|
|
|
public function getSlugOrTitleAttribute() |
|
|
|
|
84
|
|
|
{ |
85
|
|
|
if ($this->slug != '') { |
|
|
|
|
86
|
|
|
return $this->slug; |
|
|
|
|
87
|
|
|
} |
88
|
|
|
|
89
|
|
|
return $this->title; |
|
|
|
|
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
/* |
93
|
|
|
|-------------------------------------------------------------------------- |
94
|
|
|
| MUTATORS |
95
|
|
|
|-------------------------------------------------------------------------- |
96
|
|
|
*/ |
97
|
|
|
} |
98
|
|
|
|
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.