2
2
3
3
namespace App \Models ;
4
4
5
+ use App \Models \Concerns \Approvable ;
6
+ use App \Models \Concerns \HasAuthor ;
5
7
use Illuminate \Database \Eloquent \Builder ;
6
8
use Illuminate \Database \Eloquent \Factories \HasFactory ;
7
9
use Illuminate \Database \Eloquent \Model ;
14
16
15
17
class Comment extends Model
16
18
{
17
- use Chartable, HasFactory, Likeable, SoftDeletes;
19
+ use Chartable, HasFactory, Likeable, SoftDeletes, Approvable, HasAuthor ;
18
20
19
21
/**
20
22
* The attributes that are mass assignable.
@@ -67,16 +69,6 @@ public function parent()
67
69
return $ this ->belongsTo (static ::class, 'parent_id ' );
68
70
}
69
71
70
- /**
71
- * Verify if the current comment is approved.
72
- *
73
- * @return bool
74
- */
75
- public function isApproved (): bool
76
- {
77
- return $ this ->attributes ['approved ' ] === 1 || $ this ->attributes ['approved ' ] === true ;
78
- }
79
-
80
72
/**
81
73
* Verify if the current comment is a reply from another comment.
82
74
*
@@ -97,28 +89,6 @@ public function hasReplies(): bool
97
89
return count ($ this ->replies ) > 0 ;
98
90
}
99
91
100
- /**
101
- * Get the author of the comment.
102
- *
103
- * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
104
- */
105
- public function author (): BelongsTo
106
- {
107
- return $ this ->belongsTo (User::class, 'user_id ' );
108
- }
109
-
110
- /**
111
- * Where clause for only approved comments.
112
- *
113
- * @param Builder $query
114
- *
115
- * @return Builder
116
- */
117
- public function scopeApproved (Builder $ query ): Builder
118
- {
119
- return $ query ->where ('approved ' , 1 );
120
- }
121
-
122
92
/**
123
93
* Convert URLs in text to HTML links.
124
94
*
0 commit comments