Files
bogazici-api/app/Http/Resources/CategoryResource.php
2026-03-27 10:41:54 +03:00

39 lines
1.1 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
namespace App\Http\Resources;
use App\Models\Category;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
/**
* @mixin Category
*/
class CategoryResource extends JsonResource
{
/**
* @return array<string, mixed>
*/
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'slug' => $this->slug,
'label' => $this->label,
'desc' => $this->desc,
'image' => $this->image,
'meta_title' => $this->meta_title,
'meta_description' => $this->meta_description,
'courses_count' => $this->whenCounted('courses'),
// Mega menu kartında gösterilecek kurslar (menu_order 1-3)
'menu_courses' => $this->whenLoaded('menuCourses', fn () => $this->menuCourses->map(fn ($c) => [
'title' => $c->title,
'slug' => $c->slug,
])
),
'created_at' => $this->created_at?->toISOString(),
'updated_at' => $this->updated_at?->toISOString(),
];
}
}