|
@@ -4,40 +4,38 @@
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
use Carbon\Carbon;
|
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Http\Request;
|
|
|
-use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
use Illuminate\Http\Resources\Json\AnonymousResourceCollection;
|
|
|
-use App\Models\Student;
|
|
|
|
|
|
|
+use Illuminate\Http\Resources\Json\JsonResource;
|
|
|
|
|
|
|
|
class StudentResource extends JsonResource
|
|
class StudentResource extends JsonResource
|
|
|
{
|
|
{
|
|
|
- /**
|
|
|
|
|
- * Transform the resource into an array.
|
|
|
|
|
- *
|
|
|
|
|
- * @return array<string, mixed>
|
|
|
|
|
- */
|
|
|
|
|
public function toArray(Request $request): array
|
|
public function toArray(Request $request): array
|
|
|
{
|
|
{
|
|
|
return [
|
|
return [
|
|
|
- 'id' => $this->id,
|
|
|
|
|
- 'name' => $this->name,
|
|
|
|
|
- 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
|
|
|
|
|
- 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
|
|
|
|
|
- // Add your fields here
|
|
|
|
|
-
|
|
|
|
|
- // Conditional fields
|
|
|
|
|
- // $this->mergeWhen($request->user()?->isAdmin(), [
|
|
|
|
|
- // 'internal_notes' => $this->internal_notes,
|
|
|
|
|
- // ]),
|
|
|
|
|
-
|
|
|
|
|
- // Relationships
|
|
|
|
|
- // 'user' => new UserResource($this->whenLoaded('user')),
|
|
|
|
|
|
|
+ 'id' => $this->id,
|
|
|
|
|
+ 'unit_id' => $this->unit_id,
|
|
|
|
|
+ 'name' => $this->name,
|
|
|
|
|
+ 'birth_date' => $this->birth_date?->format('Y-m-d'),
|
|
|
|
|
+ 'document_number' => $this->document_number,
|
|
|
|
|
+ 'gender' => $this->gender,
|
|
|
|
|
+ 'email' => $this->email,
|
|
|
|
|
+ 'phone' => $this->phone,
|
|
|
|
|
+ 'postal_code' => $this->postal_code,
|
|
|
|
|
+ 'street' => $this->street,
|
|
|
|
|
+ 'address_number' => $this->address_number,
|
|
|
|
|
+ 'neighborhood' => $this->neighborhood,
|
|
|
|
|
+ 'city_id' => $this->city_id,
|
|
|
|
|
+ 'state_id' => $this->state_id,
|
|
|
|
|
+ 'complement' => $this->complement,
|
|
|
|
|
+ 'payer_name' => $this->payer_name,
|
|
|
|
|
+ 'how_did_you_know_us' => $this->how_did_you_know_us,
|
|
|
|
|
+ 'notes' => $this->notes,
|
|
|
|
|
+ 'status' => $this->status,
|
|
|
|
|
+ 'created_at' => Carbon::parse($this->created_at)->format('Y-m-d H:i:s'),
|
|
|
|
|
+ 'updated_at' => Carbon::parse($this->updated_at)->format('Y-m-d H:i:s'),
|
|
|
];
|
|
];
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
- /**
|
|
|
|
|
- * @param \Illuminate\Database\Eloquent\Collection<Student> $resource
|
|
|
|
|
- * @return \Illuminate\Http\Resources\Json\AnonymousResourceCollection<StudentResource>
|
|
|
|
|
- */
|
|
|
|
|
public static function collection($resource): AnonymousResourceCollection
|
|
public static function collection($resource): AnonymousResourceCollection
|
|
|
{
|
|
{
|
|
|
return parent::collection($resource);
|
|
return parent::collection($resource);
|