1 | <?php |
||
43 | class Testimonial extends Model |
||
44 | { |
||
45 | use ValidatingTrait; |
||
46 | use CacheableEloquent; |
||
47 | |||
48 | /** |
||
49 | * {@inheritdoc} |
||
50 | */ |
||
51 | protected $fillable = [ |
||
52 | 'subject_id', |
||
53 | 'subject_type', |
||
54 | 'attestant_id', |
||
55 | 'attestant_type', |
||
56 | 'is_approved', |
||
57 | 'body', |
||
58 | ]; |
||
59 | |||
60 | /** |
||
61 | * {@inheritdoc} |
||
62 | */ |
||
63 | protected $casts = [ |
||
64 | 'subject_id' => 'integer', |
||
65 | 'subject_type' => 'string', |
||
66 | 'attestant_id' => 'integer', |
||
67 | 'attestant_type' => 'string', |
||
68 | 'is_approved' => 'boolean', |
||
69 | 'body' => 'string', |
||
70 | 'deleted_at' => 'datetime', |
||
71 | ]; |
||
72 | |||
73 | /** |
||
74 | * {@inheritdoc} |
||
75 | */ |
||
76 | protected $observables = [ |
||
77 | 'validating', |
||
78 | 'validated', |
||
79 | ]; |
||
80 | |||
81 | /** |
||
82 | * The default rules that the model will validate against. |
||
83 | * |
||
84 | * @var array |
||
85 | */ |
||
86 | protected $rules = [ |
||
87 | 'subject_id' => 'required|integer', |
||
88 | 'subject_type' => 'required|string|max:150', |
||
89 | 'attestant_id' => 'required|integer', |
||
90 | 'attestant_type' => 'required|string|max:150', |
||
91 | 'is_approved' => 'sometimes|boolean', |
||
92 | 'body' => 'required|string|max:150', |
||
93 | ]; |
||
94 | |||
95 | /** |
||
96 | * Whether the model should throw a |
||
97 | * ValidationException if it fails validation. |
||
98 | * |
||
99 | * @var bool |
||
100 | */ |
||
101 | protected $throwValidationExceptions = true; |
||
102 | |||
103 | /** |
||
104 | * Create a new Eloquent model instance. |
||
105 | * |
||
106 | * @param array $attributes |
||
107 | */ |
||
108 | public function __construct(array $attributes = []) |
||
114 | |||
115 | /** |
||
116 | * Get testimonials of the given subject. |
||
117 | * |
||
118 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
119 | * @param \Illuminate\Database\Eloquent\Model $subject |
||
120 | * |
||
121 | * @return \Illuminate\Database\Eloquent\Builder |
||
122 | */ |
||
123 | public function scopeOfSubject(Builder $builder, Model $subject): Builder |
||
127 | |||
128 | /** |
||
129 | * Get testimonials of the given attestant. |
||
130 | * |
||
131 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
132 | * @param \Illuminate\Database\Eloquent\Model $attestant |
||
133 | * |
||
134 | * @return \Illuminate\Database\Eloquent\Builder |
||
135 | */ |
||
136 | public function scopeOfAttestant(Builder $builder, Model $attestant): Builder |
||
140 | |||
141 | /** |
||
142 | * Get the approved testimonials. |
||
143 | * |
||
144 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
145 | * |
||
146 | * @return \Illuminate\Database\Eloquent\Builder |
||
147 | */ |
||
148 | public function scopeApproved(Builder $builder): Builder |
||
152 | |||
153 | /** |
||
154 | * Get the disapproved testimonials. |
||
155 | * |
||
156 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
157 | * |
||
158 | * @return \Illuminate\Database\Eloquent\Builder |
||
159 | */ |
||
160 | public function scopeDisapproved(Builder $builder): Builder |
||
164 | |||
165 | /** |
||
166 | * Get the subject model of the testimonial. |
||
167 | * |
||
168 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
169 | */ |
||
170 | public function subject(): MorphTo |
||
174 | |||
175 | /** |
||
176 | * Get the attestant model of the testimonial. |
||
177 | * |
||
178 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
179 | */ |
||
180 | public function attestant(): MorphTo |
||
184 | |||
185 | /** |
||
186 | * Approve the testimonial. |
||
187 | * |
||
188 | * @return $this |
||
189 | */ |
||
190 | public function approve() |
||
196 | |||
197 | /** |
||
198 | * Disapprove the testimonial. |
||
199 | * |
||
200 | * @return $this |
||
201 | */ |
||
202 | public function disapprove() |
||
208 | } |
||
209 |
Overly long lines are hard to read on any screen. Most code styles therefor impose a maximum limit on the number of characters in a line.