*/ use HasFactory; /** Rating categories besides the overall rating, with their German labels. */ public const CATEGORIES = [ 'rating_cleanliness' => 'Sauberkeit', 'rating_equipment' => 'Ausstattung', 'rating_location' => 'Lage', 'rating_host' => 'Gastgeber', ]; protected static function booted(): void { static::saving(function (Review $review): void { if ($review->status === ReviewStatus::Approved && $review->approved_at === null) { $review->approved_at = now(); } if ($review->isDirty('response')) { $review->responded_at = filled($review->response) ? now() : null; } }); } /** * Get the attributes that should be cast. * * @return array */ protected function casts(): array { return [ 'status' => ReviewStatus::class, 'publish_consent' => 'boolean', 'stayed_on' => 'immutable_date', 'responded_at' => 'immutable_datetime', 'approved_at' => 'immutable_datetime', ]; } /** * @return BelongsTo */ public function property(): BelongsTo { return $this->belongsTo(Property::class); } /** * @return BelongsTo */ public function booking(): BelongsTo { return $this->belongsTo(Booking::class); } /** * Reviews that may be shown on the website. * * @param Builder $query * @return Builder */ #[Scope] protected function published(Builder $query): Builder { return $query ->where('status', ReviewStatus::Approved) ->where('publish_consent', true) ->latest('stayed_on'); } }