first work on To Do Lists
This commit is contained in:
35
app/Http/Resources/ToDo.php
Normal file
35
app/Http/Resources/ToDo.php
Normal file
@@ -0,0 +1,35 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ToDo extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
'type' => 'to-dos',
|
||||
'to_do_id' => $this->id,
|
||||
'attributes' => [
|
||||
'data' => [
|
||||
'name' => $this->name,
|
||||
'order' => $this->order,
|
||||
'checked_at' => optional($this->checked_at)->diffForHumans(),
|
||||
'last_updated' => $this->updated_at->diffForHumans(),
|
||||
]
|
||||
]
|
||||
],
|
||||
'links' => [
|
||||
'self' => url('/to-do-lists/'.$this->to_do_list_id),
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
22
app/Http/Resources/ToDoCollection.php
Normal file
22
app/Http/Resources/ToDoCollection.php
Normal file
@@ -0,0 +1,22 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use Illuminate\Http\Resources\Json\ResourceCollection;
|
||||
|
||||
class ToDoCollection extends ResourceCollection
|
||||
{
|
||||
/**
|
||||
* Transform the resource collection into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => $this->collection,
|
||||
'to_dos_count' => $this->count(),
|
||||
];
|
||||
}
|
||||
}
|
||||
38
app/Http/Resources/ToDoList.php
Normal file
38
app/Http/Resources/ToDoList.php
Normal file
@@ -0,0 +1,38 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Resources;
|
||||
|
||||
use App\Http\Resources\User as UserResource;
|
||||
use Illuminate\Http\Resources\Json\JsonResource;
|
||||
|
||||
class ToDoList extends JsonResource
|
||||
{
|
||||
/**
|
||||
* Transform the resource into an array.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return array
|
||||
*/
|
||||
public function toArray($request)
|
||||
{
|
||||
return [
|
||||
'data' => [
|
||||
'type' => 'to-do-lists',
|
||||
'to_do_list_id' => $this->id,
|
||||
'attributes' => [
|
||||
'data' => [
|
||||
'name' => $this->name,
|
||||
'to_dos' => new ToDoCollection($this->toDos),
|
||||
'posted_by' => new UserResource($this->user),
|
||||
'last_updated' => $this->updated_at->diffForHumans(),
|
||||
// 'cover_image' => new ImageResource($this->coverImage),
|
||||
]
|
||||
]
|
||||
//'tags' => TagResource::collection($this->tags),
|
||||
],
|
||||
'links' => [
|
||||
'self' => $this->path(),
|
||||
]
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user