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