api/app/Http/Resources/ReportResource.php

39 lines
1.0 KiB
PHP

<?php
namespace App\Http\Resources;
use App\Models\MealPosts;
use App\Models\Report;
use App\Models\User;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/** @mixin Report */
class ReportResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'reason' => $this->reason,
'reasonLabel' => $this->reason?->getLabel(),
'details' => $this->details,
'status' => $this->status,
'statusLabel' => $this->status?->getLabel(),
'reportableType' => $this->reportableType(),
'reportableId' => $this->reportable_id,
'moderationCaseId' => $this->moderation_case_id,
'createdAt' => $this->created_at,
];
}
private function reportableType(): string
{
return match ($this->reportable_type) {
MealPosts::class => 'meal_post',
User::class => 'user',
default => 'unknown',
};
}
}