|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace App\Model; |
|
4
|
|
|
|
|
5
|
|
|
use Carbon\Carbon; |
|
6
|
|
|
use Illuminate\Database\Eloquent\SoftDeletes; |
|
7
|
|
|
use Illuminate\Database\Eloquent\Model as EloquentModel; |
|
8
|
|
|
|
|
9
|
|
|
/** |
|
10
|
|
|
* Class Redirect. |
|
11
|
|
|
* |
|
12
|
|
|
* @property int $id |
|
13
|
|
|
* @property mixed $fromPage |
|
14
|
|
|
* @property mixed $to |
|
15
|
|
|
* @property int $creator_id |
|
16
|
|
|
* @property int $modifier_id |
|
17
|
|
|
* |
|
18
|
|
|
* @property Carbon $deleted_at |
|
19
|
|
|
* @property Carbon $created_at |
|
20
|
|
|
* @property Carbon $updated_at |
|
21
|
|
|
*/ |
|
22
|
|
|
class Redirect extends EloquentModel |
|
23
|
|
|
{ |
|
24
|
|
|
|
|
25
|
|
|
/* |
|
26
|
|
|
* Laravel Deleting. |
|
27
|
|
|
* @ https://laravel.com/docs/5.5/eloquent#soft-deleting |
|
28
|
|
|
*/ |
|
29
|
|
|
use SoftDeletes; |
|
30
|
|
|
|
|
31
|
|
|
/** |
|
32
|
|
|
* The table associated with the model. |
|
33
|
|
|
* |
|
34
|
|
|
* @var string |
|
35
|
|
|
*/ |
|
36
|
|
|
protected $table = 'redirects'; |
|
37
|
|
|
|
|
38
|
|
|
/** |
|
39
|
|
|
* The table date columns, casted to Carbon. |
|
40
|
|
|
* |
|
41
|
|
|
* @var array |
|
42
|
|
|
*/ |
|
43
|
|
|
protected $dates = ['created_at', 'updated_at', 'deleted_at']; |
|
44
|
|
|
|
|
45
|
|
|
|
|
46
|
|
|
|
|
47
|
|
|
public function from() |
|
48
|
|
|
{ |
|
49
|
|
|
if (is_numeric($this->getAttribute('from'))) { |
|
50
|
|
|
return makeSlug($this->fromPage); |
|
51
|
|
|
} else { |
|
52
|
|
|
return $this->getAttribute('from'); |
|
53
|
|
|
} |
|
54
|
|
|
} |
|
55
|
|
|
|
|
56
|
|
|
public function setFrom($string) |
|
57
|
|
|
{ |
|
58
|
|
|
$this->setAttribute('from', $string); |
|
59
|
|
|
|
|
60
|
|
|
return $this; |
|
61
|
|
|
} |
|
62
|
|
|
|
|
63
|
|
|
public function to() |
|
64
|
|
|
{ |
|
65
|
|
|
if (is_numeric($this->getAttribute('to'))) { |
|
66
|
|
|
return makeSlug($this->toPage); |
|
67
|
|
|
} else { |
|
68
|
|
|
return $this->getAttribute('to'); |
|
69
|
|
|
} |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
public function setTo($string) |
|
73
|
|
|
{ |
|
74
|
|
|
$this->setAttribute('to', $string); |
|
75
|
|
|
|
|
76
|
|
|
return $this; |
|
77
|
|
|
} |
|
78
|
|
|
|
|
79
|
|
|
/** |
|
80
|
|
|
* @param int $integer |
|
81
|
|
|
* @return $this |
|
82
|
|
|
*/ |
|
83
|
|
|
public function setCreatorID(int $integer) |
|
84
|
|
|
{ |
|
85
|
|
|
$this->setAttribute('creator_id', $integer); |
|
86
|
|
|
|
|
87
|
|
|
return $this; |
|
88
|
|
|
} |
|
89
|
|
|
|
|
90
|
|
|
public function creator() |
|
91
|
|
|
{ |
|
92
|
|
|
return $this->belongsTo(Account::class, 'creator_id', 'id'); |
|
93
|
|
|
} |
|
94
|
|
|
|
|
95
|
|
|
public function modifier() |
|
96
|
|
|
{ |
|
97
|
|
|
if ($this->getAttribute('modifier_id')) { |
|
98
|
|
|
return $this->belongsTo(Account::class, 'modifier_id', 'id'); |
|
99
|
|
|
} |
|
100
|
|
|
} |
|
101
|
|
|
|
|
102
|
|
|
public function deleted_at() |
|
|
|
|
|
|
103
|
|
|
{ |
|
104
|
|
|
return $this->getAttribute('deleted_at'); |
|
105
|
|
|
} |
|
106
|
|
|
|
|
107
|
|
|
public function updated_at() |
|
|
|
|
|
|
108
|
|
|
{ |
|
109
|
|
|
return $this->getAttribute('updated_at'); |
|
110
|
|
|
} |
|
111
|
|
|
|
|
112
|
|
|
public function created_at() |
|
|
|
|
|
|
113
|
|
|
{ |
|
114
|
|
|
return $this->getAttribute('created_at'); |
|
115
|
|
|
} |
|
116
|
|
|
|
|
117
|
|
|
public function isEnabled() |
|
118
|
|
|
{ |
|
119
|
|
|
return $this->deleted_at() ? false : true; |
|
120
|
|
|
} |
|
121
|
|
|
|
|
122
|
|
|
public function lastEditor() |
|
123
|
|
|
{ |
|
124
|
|
|
return $this->modifier() ?: $this->creator(); |
|
125
|
|
|
} |
|
126
|
|
|
|
|
127
|
|
|
/** |
|
128
|
|
|
* @return Page|mixed |
|
|
|
|
|
|
129
|
|
|
*/ |
|
130
|
|
|
public function fromPage() |
|
131
|
|
|
{ |
|
132
|
|
|
return $this->belongsTo(Page::class, 'from', 'id'); |
|
133
|
|
|
} |
|
134
|
|
|
|
|
135
|
|
|
/** |
|
136
|
|
|
* @return Page|mixed |
|
|
|
|
|
|
137
|
|
|
*/ |
|
138
|
|
|
public function toPage() |
|
139
|
|
|
{ |
|
140
|
|
|
return $this->belongsTo(Page::class, 'to', 'id'); |
|
141
|
|
|
} |
|
142
|
|
|
} |
|
143
|
|
|
|
This check looks for method names that are not written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection seeker becomes
databaseConnectionSeeker.