finished api
This commit is contained in:
24
laravel/app/Http/Resources/BilletResource.php
Normal file
24
laravel/app/Http/Resources/BilletResource.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class BilletResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'Date' => $this->BIL_DATE,
|
||||
'Titre' => $this->BIL_TITRE,
|
||||
'Contenu' => $this->BIL_CONTENU,
|
||||
'Commentaires' => CommentaireResource::collection($this->whenLoaded('commentaires')),
|
||||
];
|
||||
}
|
||||
}
|
||||
23
laravel/app/Http/Resources/BilletsResource.php
Normal file
23
laravel/app/Http/Resources/BilletsResource.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class BilletsResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'Date' => $this->BIL_DATE,
|
||||
'Titre' => $this->BIL_TITRE,
|
||||
'Contenu' => $this->BIL_CONTENU,
|
||||
];
|
||||
}
|
||||
}
|
||||
23
laravel/app/Http/Resources/CommentaireResource.php
Normal file
23
laravel/app/Http/Resources/CommentaireResource.php
Normal file
@@ -0,0 +1,23 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class CommentaireResource extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'Date' => $this->COM_DATE,
|
||||
'Auteur' => $this->user->name,
|
||||
'Contenu' => $this->COM_CONTENU,
|
||||
];
|
||||
}
|
||||
}
|
||||
24
laravel/app/Http/Resources/UserResource.php
Normal file
24
laravel/app/Http/Resources/UserResource.php
Normal file
@@ -0,0 +1,24 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class UserResource extends JsonResource
|
||||
{
|
||||
public static $wrap = 'user';
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function toArray(Request $request): array
|
||||
{
|
||||
return [
|
||||
'id' => $this->getKey(),
|
||||
'nom' => $this->name,
|
||||
'email' => $this->email,
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user