62 lines
1.5 KiB
PHP
62 lines
1.5 KiB
PHP
<?php namespace App\Http\Controllers\App;
|
|
|
|
use App\Models\Inventory;
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\App\InventoryStoreRequest;
|
|
use App\Http\Requests\App\InventoryUpdateRequest;
|
|
use App\Services\ProductService;
|
|
use Notsoweb\ApiResponse\Enums\ApiResponse;
|
|
|
|
|
|
class InventoryController extends Controller
|
|
{
|
|
public function __construct(
|
|
protected ProductService $productService
|
|
) {}
|
|
|
|
public function index()
|
|
{
|
|
$products = Inventory::with(['category', 'price'])
|
|
->where('is_active', true)
|
|
->orderBy('name')
|
|
->paginate(config('app.pagination'));
|
|
|
|
return ApiResponse::OK->response([
|
|
'products' => $products
|
|
]);
|
|
}
|
|
|
|
public function show(Inventory $inventario)
|
|
{
|
|
return ApiResponse::OK->response([
|
|
'model' => $inventario->load(['category', 'price'])
|
|
]);
|
|
}
|
|
|
|
public function store(InventoryStoreRequest $request)
|
|
{
|
|
$product = $this->productService->createProduct($request->validated());
|
|
|
|
return ApiResponse::OK->response([
|
|
'model' => $product
|
|
]);
|
|
}
|
|
|
|
public function update(InventoryUpdateRequest $request, Inventory $inventario)
|
|
{
|
|
$product = $this->productService->updateProduct($inventario, $request->validated());
|
|
|
|
return ApiResponse::OK->response([
|
|
'model' => $product
|
|
]);
|
|
}
|
|
|
|
public function destroy(Inventory $inventario)
|
|
{
|
|
$inventario->delete();
|
|
|
|
return ApiResponse::OK->response();
|
|
}
|
|
|
|
}
|