41 lines
1.1 KiB
PHP
41 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Resources;
|
|
|
|
use App\Models\MealPosts;
|
|
use App\Models\PostReviews;
|
|
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',
|
|
PostReviews::class => 'post_review',
|
|
User::class => 'user',
|
|
default => 'unknown',
|
|
};
|
|
}
|
|
}
|