Resource trong Laravel

04/01/2022   Laravel
Resource trong Laravel
1. Resource trong Laravel
- Để định dạng dữ liệu trả về cho API call
- Ví dụng trong controller
-----------------------------------
+ return TaskResource::collection($tasks);
+ return new TaskResource($task);
-----------------------------------
- Ví dụ trong resource
-----------------------------------
return [
'title'=>$this->title,
'todo_list'=>$this->todoList->name,
'todo_label'=>new TodoLabelResource($this->todoLabel),
'created_at'=>$this->created_at->diffForHumans()
];
-----------------------------------

