Service & Repository Pattern
서론
구조 설계
Controller
class ProductController extends Controller
{
private $productService;
public function __construct(ProductService $productService)
{
$this->productService = $productService;
}
public function store(ProductRequest $request)
{
$response = [
'result' => true,
'message' => '상품 등록 성공',
'data' => [],
];
try {
$validated = $request->validated();
$response['data'] = $this->productService->create($validated);
} catch (\Throwable $th) {
$response['result'] = false;
$response['message'] = $th->getMessage();
}
return $response;
}
}Service
Repository
구현
Last updated