Files
fitness/app/Http/Resources/WorkoutResource.php
T

33 lines
1.2 KiB
PHP
Raw Normal View History

2026-08-10 19:18:25 +03:00
<?php
namespace App\Http\Resources;
use Illuminate\Http\Request;
use Illuminate\Http\Resources\Json\JsonResource;
class WorkoutResource extends JsonResource
{
public function toArray(Request $request): array
{
return [
'id' => $this->id,
'user_id' => $this->user_id,
'owner' => new UserResource($this->whenLoaded('user')),
'title' => $this->title,
'notes' => $this->notes,
'estimated_minutes' => $this->estimated_minutes,
'is_public' => (bool) $this->is_public,
'program_id' => $this->program_id,
'week_number' => $this->week_number,
'day_number' => $this->day_number,
'assigned_by_trainer_id' => $this->assigned_by_trainer_id,
'assigned_by_trainer' => new UserResource($this->whenLoaded('assignedByTrainer')),
'items' => WorkoutExerciseResource::collection($this->whenLoaded('items')),
'is_favorited' => $request->user()
? $request->user()->favoriteWorkouts()->where('workout_id', $this->id)->exists()
: false,
'created_at' => $this->created_at,
];
}
}