*/ protected $fillable = [ 'type', 'name', 'email', 'phone', 'company', 'country_region', 'industry', 'topic', 'message', 'status', 'handled_at', 'meta', ]; /** * The attributes that should be cast. * * @var array */ protected $casts = [ 'meta' => 'array', 'handled_at' => 'datetime', 'created_at' => 'datetime', 'updated_at' => 'datetime', ]; /** * Default values for attributes. * * @var array */ protected $attributes = [ 'type' => 'general', 'status' => 'new', ]; /** * Scope a query to only include new submissions. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeNew($query) { return $query->where('status', 'new'); } /** * Scope a query to only include handled submissions. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeHandled($query) { return $query->where('status', 'handled'); } /** * Scope a query to only include spam submissions. * * @param \Illuminate\Database\Eloquent\Builder $query * @return \Illuminate\Database\Eloquent\Builder */ public function scopeSpam($query) { return $query->where('status', 'spam'); } /** * Scope a query to filter by type. * * @param \Illuminate\Database\Eloquent\Builder $query * @param string $type * @return \Illuminate\Database\Eloquent\Builder */ public function scopeOfType($query, string $type) { return $query->where('type', $type); } /** * Mark the submission as handled. * * @return bool */ public function markAsHandled(): bool { return $this->update([ 'status' => 'handled', 'handled_at' => now(), ]); } /** * Mark the submission as spam. * * @return bool */ public function markAsSpam(): bool { return $this->update([ 'status' => 'spam', ]); } /** * Check if submission is new. * * @return bool */ public function isNew(): bool { return $this->status === 'new'; } /** * Check if submission is handled. * * @return bool */ public function isHandled(): bool { return $this->status === 'handled'; } /** * Check if submission is spam. * * @return bool */ public function isSpam(): bool { return $this->status === 'spam'; } /** * Get form source from meta. * * @return string|null */ public function getFormSourceAttribute(): ?string { return $this->meta['form_source'] ?? null; } }