1 | <?php |
||
37 | class Testimonial extends Model implements TestimonialContract |
||
38 | { |
||
39 | use ValidatingTrait; |
||
40 | use CacheableEloquent; |
||
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | protected $fillable = [ |
||
46 | 'user_id', |
||
47 | 'is_approved', |
||
48 | 'body', |
||
49 | ]; |
||
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | protected $casts = [ |
||
55 | 'user_id' => 'integer', |
||
56 | 'is_approved' => 'boolean', |
||
57 | 'body' => 'string', |
||
58 | 'deleted_at' => 'datetime', |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * {@inheritdoc} |
||
63 | */ |
||
64 | protected $observables = [ |
||
65 | 'validating', |
||
66 | 'validated', |
||
67 | ]; |
||
68 | |||
69 | /** |
||
70 | * The default rules that the model will validate against. |
||
71 | * |
||
72 | * @var array |
||
73 | */ |
||
74 | protected $rules = [ |
||
75 | 'user_id' => 'required|integer', |
||
76 | 'is_approved' => 'sometimes|boolean', |
||
77 | 'body' => 'required|string|max:150', |
||
78 | ]; |
||
79 | |||
80 | /** |
||
81 | * Whether the model should throw a |
||
82 | * ValidationException if it fails validation. |
||
83 | * |
||
84 | * @var bool |
||
85 | */ |
||
86 | protected $throwValidationExceptions = true; |
||
87 | |||
88 | /** |
||
89 | * Create a new Eloquent model instance. |
||
90 | * |
||
91 | * @param array $attributes |
||
92 | */ |
||
93 | public function __construct(array $attributes = []) |
||
99 | |||
100 | /** |
||
101 | * Get the approved testimonials. |
||
102 | * |
||
103 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
104 | * |
||
105 | * @return \Illuminate\Database\Eloquent\Builder |
||
106 | */ |
||
107 | public function scopeApproved(Builder $builder): Builder |
||
111 | |||
112 | /** |
||
113 | * Get the disapproved testimonials. |
||
114 | * |
||
115 | * @param \Illuminate\Database\Eloquent\Builder $builder |
||
116 | * |
||
117 | * @return \Illuminate\Database\Eloquent\Builder |
||
118 | */ |
||
119 | public function scopeDisapproved(Builder $builder): Builder |
||
123 | |||
124 | /** |
||
125 | * Get the owner model of the testimonial. |
||
126 | * |
||
127 | * @return \Illuminate\Database\Eloquent\Relations\BelongsTo |
||
128 | */ |
||
129 | public function user(): belongsTo |
||
133 | |||
134 | /** |
||
135 | * Approve the testimonial. |
||
136 | * |
||
137 | * @return $this |
||
138 | */ |
||
139 | public function approve() |
||
145 | |||
146 | /** |
||
147 | * Disapprove the testimonial. |
||
148 | * |
||
149 | * @return $this |
||
150 | */ |
||
151 | public function disapprove() |
||
157 | } |
||
158 |