가이드
일괄 작업
엔티티를 일괄로 관리하는 방법을 알아봅니다.
모델과 연관관계 모두에서 다음과 같은 일괄 작업이 지원됩니다: store, update, destroy, restore.
일괄 저장
이 엔드포인트는 요청 페이로드에 resources 배열을 가진 객체를 기대하며, 배열의 각 항목은 생성할 리소스(예: 게시글)를 나타내는 객체입니다.
// (POST) https://myapp.com/api/posts/batch
{
"resources" : [
{
"title" : "My Post 1",
"body" : "Example body text"
},
{
"title" : "My Post 2",
"body" : "Example body text"
}
]
}
일괄 수정
이 엔드포인트는 요청 페이로드에 resources 객체를 가진 객체를 기대하며, 각 키는 리소스 id이고 각 항목은 수정할 리소스(예: 게시글)를 나타내는 객체입니다.
// (PATCH) https://myapp.com/api/posts/batch
{
"resources" : {
"5" : {
"title" : "My Post 1 (updated)",
"body" : "Example updated body text"
},
"6": {
"title" : "My Post 2",
"body" : "Example body text"
}
}
}
일괄 삭제
이 엔드포인트는 요청 페이로드에 resources 배열을 가진 객체를 기대하며, 배열의 각 항목은 삭제할 리소스(예: 게시글)의 id입니다.
// (DELETE) https://myapp.com/api/posts/batch
{
"resources" : [5,6]
}
일괄 복원
이 엔드포인트는 요청 페이로드에 resources 배열을 가진 객체를 기대하며, 배열의 각 항목은 복원할 리소스(예: 게시글)의 id입니다.
// (POST) https://myapp.com/api/posts/batch/restore
{
"resources" : [5,6]
}
일괄 작업 비활성화
일괄 작업은 모든 리소스에서 기본적으로 활성화되어 있습니다. 특정 엔드포인트를 비활성화하려면 Laravel의 except 메서드를 사용할 수 있습니다:
Orion::resource('posts', PostsController::class)->except(['batchStore', 'batchUpdate']);
리소스의 모든 일괄 작업을 비활성화하려면 withoutBatch 메서드를 사용할 수 있습니다:
Orion::resource('posts', PostsController::class)->withoutBatch();