taktik - laravel
This commit is contained in:
63
app/Http/Resources/CategoryResource.php
Normal file
63
app/Http/Resources/CategoryResource.php
Normal file
@@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Models\Category;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
use OpenApi\Annotations as OA;
|
||||
|
||||
/**
|
||||
* @mixin Category
|
||||
* @OA\Schema(
|
||||
* schema="CategoryResource",
|
||||
* type="object",
|
||||
* title="Category Resource",
|
||||
* description="Resource representing a single category",
|
||||
* @OA\Property(
|
||||
* property="id",
|
||||
* type="integer",
|
||||
* description="ID of the category",
|
||||
* example=1
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="name",
|
||||
* type="string",
|
||||
* description="Name of the category",
|
||||
* example="Technology"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="created_at",
|
||||
* type="string",
|
||||
* format="date-time",
|
||||
* description="Timestamp when the category was created",
|
||||
* example="2023-12-10T14:17:00Z"
|
||||
* ),
|
||||
* @OA\Property(
|
||||
* property="updated_at",
|
||||
* type="string",
|
||||
* format="date-time",
|
||||
* description="Timestamp when the category was last updated",
|
||||
* example="2023-12-11T15:20:00Z"
|
||||
* )
|
||||
* )
|
||||
*/
|
||||
class CategoryResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->id,
|
||||
'name' => $this->name,
|
||||
'created_at' => $this->created_at->toDateTimeString(),
|
||||
'updated_at' => $this->updated_at->toDateTimeString(),
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user