1 | <?php |
||
42 | class Testimonial extends Model |
||
43 | { |
||
44 | use ValidatingTrait; |
||
45 | |||
46 | /** |
||
47 | * {@inheritdoc} |
||
48 | */ |
||
49 | protected $fillable = [ |
||
50 | 'subject_id', |
||
51 | 'subject_type', |
||
52 | 'attestant_id', |
||
53 | 'attestant_type', |
||
54 | 'is_approved', |
||
55 | 'body', |
||
56 | ]; |
||
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | protected $casts = [ |
||
62 | 'subject_id' => 'integer', |
||
63 | 'subject_type' => 'string', |
||
64 | 'attestant_id' => 'integer', |
||
65 | 'attestant_type' => 'string', |
||
66 | 'is_approved' => 'boolean', |
||
67 | 'body' => 'string', |
||
68 | 'deleted_at' => 'datetime', |
||
69 | ]; |
||
70 | |||
71 | /** |
||
72 | * {@inheritdoc} |
||
73 | */ |
||
74 | protected $observables = [ |
||
75 | 'validating', |
||
76 | 'validated', |
||
77 | ]; |
||
78 | |||
79 | /** |
||
80 | * The default rules that the model will validate against. |
||
81 | * |
||
82 | * @var array |
||
83 | */ |
||
84 | protected $rules = [ |
||
85 | 'subject_id' => 'required|integer', |
||
86 | 'subject_type' => 'required|string|strip_tags|max:150', |
||
87 | 'attestant_id' => 'required|integer', |
||
88 | 'attestant_type' => 'required|string|strip_tags|max:150', |
||
89 | 'is_approved' => 'sometimes|boolean', |
||
90 | 'body' => 'required|string|strip_tags|max:150', |
||
91 | ]; |
||
92 | |||
93 | /** |
||
94 | * Whether the model should throw a |
||
95 | * ValidationException if it fails validation. |
||
96 | * |
||
97 | * @var bool |
||
98 | */ |
||
99 | protected $throwValidationExceptions = true; |
||
100 | |||
101 | /** |
||
102 | * Create a new Eloquent model instance. |
||
103 | * |
||
104 | * @param array $attributes |
||
105 | */ |
||
106 | public function __construct(array $attributes = []) |
||
112 | |||
113 | /** |
||
114 | * Get testimonials of the given subject. |
||
115 | * |
||
116 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
117 | * @param \Illuminate\Database\Eloquent\Model $subject |
||
118 | * |
||
119 | * @return \Illuminate\Database\Eloquent\Builder |
||
120 | */ |
||
121 | public function scopeOfSubject(Builder $builder, Model $subject): Builder |
||
125 | |||
126 | /** |
||
127 | * Get testimonials of the given attestant. |
||
128 | * |
||
129 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
130 | * @param \Illuminate\Database\Eloquent\Model $attestant |
||
131 | * |
||
132 | * @return \Illuminate\Database\Eloquent\Builder |
||
133 | */ |
||
134 | public function scopeOfAttestant(Builder $builder, Model $attestant): Builder |
||
138 | |||
139 | /** |
||
140 | * Get the approved testimonials. |
||
141 | * |
||
142 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
143 | * |
||
144 | * @return \Illuminate\Database\Eloquent\Builder |
||
145 | */ |
||
146 | public function scopeApproved(Builder $builder): Builder |
||
150 | |||
151 | /** |
||
152 | * Get the disapproved testimonials. |
||
153 | * |
||
154 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
155 | * |
||
156 | * @return \Illuminate\Database\Eloquent\Builder |
||
157 | */ |
||
158 | public function scopeDisapproved(Builder $builder): Builder |
||
162 | |||
163 | /** |
||
164 | * Get the subject model of the testimonial. |
||
165 | * |
||
166 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
167 | */ |
||
168 | public function subject(): MorphTo |
||
172 | |||
173 | /** |
||
174 | * Get the attestant model of the testimonial. |
||
175 | * |
||
176 | * @return \Illuminate\Database\Eloquent\Relations\MorphTo |
||
177 | */ |
||
178 | public function attestant(): MorphTo |
||
182 | |||
183 | /** |
||
184 | * Approve the testimonial. |
||
185 | * |
||
186 | * @return $this |
||
187 | */ |
||
188 | public function approve() |
||
194 | |||
195 | /** |
||
196 | * Disapprove the testimonial. |
||
197 | * |
||
198 | * @return $this |
||
199 | */ |
||
200 | public function disapprove() |
||
206 | } |
||
207 |