1 | <?php |
||
2 | |||
3 | namespace AloiaCms\Models\Traits; |
||
4 | |||
5 | use Carbon\Carbon; |
||
6 | |||
7 | trait Postable |
||
8 | { |
||
9 | /** |
||
10 | * Set the post date |
||
11 | * |
||
12 | * @param Carbon $post_date |
||
13 | * @return $this |
||
14 | */ |
||
15 | 2 | public function setPostDate(Carbon $post_date) |
|
16 | { |
||
17 | 2 | $this->matter['post_date'] = $post_date->toDateString(); |
|
0 ignored issues
–
show
Bug
Best Practice
introduced
by
![]() |
|||
18 | $this->has_changes = true; |
||
0 ignored issues
–
show
|
|||
19 | 2 | ||
20 | return $this; |
||
21 | } |
||
22 | |||
23 | /** |
||
24 | * Get the post date |
||
25 | * |
||
26 | * @return Carbon|null |
||
27 | 2 | */ |
|
28 | public function getPostDate(): ?Carbon |
||
29 | 2 | { |
|
30 | 1 | if (!isset($this->matter['post_date']) || empty($this->matter['post_date'])) { |
|
31 | return null; |
||
32 | } |
||
33 | 1 | ||
34 | return Carbon::createFromFormat('Y-m-d', $this->matter['post_date']); |
||
0 ignored issues
–
show
|
|||
35 | } |
||
36 | } |
||
37 |