Skip to content

Commit ef3149b

Browse files
committed
Convert $casts property to method
1 parent c3feb16 commit ef3149b

File tree

3 files changed

+34
-19
lines changed

3 files changed

+34
-19
lines changed

app/Models/Article.php

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -54,15 +54,6 @@ final class Article extends Model implements Feedable
5454
'shared_at',
5555
];
5656

57-
/**
58-
* {@inheritdoc}
59-
*/
60-
protected $casts = [
61-
'submitted_at' => 'datetime',
62-
'approved_at' => 'datetime',
63-
'shared_at' => 'datetime',
64-
];
65-
6657
/**
6758
* {@inheritdoc}
6859
*/
@@ -73,6 +64,20 @@ final class Article extends Model implements Feedable
7364
'tagsRelation',
7465
];
7566

67+
/**
68+
* Get the attributes that should be cast.
69+
*
70+
* @return array<string, string>
71+
*/
72+
protected function casts(): array
73+
{
74+
return [
75+
'submitted_at' => 'datetime',
76+
'approved_at' => 'datetime',
77+
'shared_at' => 'datetime',
78+
];
79+
}
80+
7681
public function id(): int
7782
{
7883
return $this->id;

app/Models/Thread.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ final class Thread extends Model implements Feedable, MentionAble, ReplyAble, Sp
8282
];
8383

8484
/**
85-
* {@inheritdoc}
85+
* Get the attributes that should be cast.
86+
*
87+
* @return array<string, string>
8688
*/
87-
protected $casts = [
88-
'last_activity_at' => 'datetime',
89-
'locked_at' => 'datetime',
90-
];
89+
protected function casts(): array
90+
{
91+
return [
92+
'last_activity_at' => 'datetime',
93+
'locked_at' => 'datetime',
94+
];
95+
}
9196

9297
public function id(): int
9398
{

app/Models/User.php

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,14 +60,19 @@ final class User extends Authenticatable implements MustVerifyEmail
6060
/**
6161
* {@inheritdoc}
6262
*/
63-
protected $casts = [
64-
'allowed_notifications' => 'array',
65-
];
63+
protected $hidden = ['password', 'remember_token'];
6664

6765
/**
68-
* {@inheritdoc}
66+
* Get the attributes that should be cast.
67+
*
68+
* @return array<string, string>
6969
*/
70-
protected $hidden = ['password', 'remember_token'];
70+
protected function casts(): array
71+
{
72+
return [
73+
'allowed_notifications' => 'array',
74+
];
75+
}
7176

7277
public function id(): int
7378
{

0 commit comments

Comments
 (0)