131 lines
4.2 KiB
PHP
131 lines
4.2 KiB
PHP
|
<?php
|
||
|
|
||
|
namespace Modules\Product\Http\Controllers;
|
||
|
|
||
|
use App\Http\Controllers\Controller;
|
||
|
use Illuminate\Http\RedirectResponse;
|
||
|
use Illuminate\Http\Request;
|
||
|
use Modules\Product\Models\Product;
|
||
|
use Modules\Product\Repositories\CategoryRepository;
|
||
|
use Modules\Product\Repositories\ProductInterface;
|
||
|
use Modules\Product\Repositories\ProductRepository;
|
||
|
use Modules\Product\Repositories\SubCategoryRepository;
|
||
|
use Modules\Product\Repositories\WarehouseRepository;
|
||
|
use Modules\Supplier\Models\Supplier;
|
||
|
use Modules\Supplier\Repositories\SupplierRepository;
|
||
|
|
||
|
class ProductController extends Controller
|
||
|
{
|
||
|
private $productRepository;
|
||
|
private $categoryRepository;
|
||
|
private $subCategoryRepository;
|
||
|
private $warehouseRepository;
|
||
|
private $supplierRepository;
|
||
|
|
||
|
/**
|
||
|
* Display a listing of the resource.
|
||
|
*/
|
||
|
public function __construct(ProductRepository $productRepository,
|
||
|
CategoryRepository $categoryRepository,
|
||
|
SubCategoryRepository $subCategoryRepository,
|
||
|
SupplierRepository $supplierRepository,
|
||
|
WarehouseRepository $warehouseRepository)
|
||
|
{
|
||
|
$this->productRepository = $productRepository;
|
||
|
$this->categoryRepository = $categoryRepository;
|
||
|
$this->subCategoryRepository = $subCategoryRepository;
|
||
|
$this->supplierRepository = $supplierRepository;
|
||
|
$this->warehouseRepository = $warehouseRepository;
|
||
|
}
|
||
|
|
||
|
public function index()
|
||
|
{
|
||
|
$data['title'] = "Product Lists";
|
||
|
$data['products'] = $this->productRepository->findAll();
|
||
|
return view('product::product.index', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the form for creating a new resource.
|
||
|
*/
|
||
|
public function create()
|
||
|
{
|
||
|
$data['title'] = 'Create Product';
|
||
|
$data['category'] = $this->categoryRepository->pluck();
|
||
|
$data['subCategory'] = $this->subCategoryRepository->pluck();
|
||
|
$data['supplier'] = $this->supplierRepository->pluck();
|
||
|
$data['warehouse'] = $this->warehouseRepository->pluck();
|
||
|
$data['status'] = Product::STATUS;
|
||
|
|
||
|
return view('product::product.create', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Store a newly created resource in storage.
|
||
|
*/
|
||
|
public function store(Request $request): RedirectResponse
|
||
|
{
|
||
|
$inputData = $request->all();
|
||
|
$this->productRepository->create($inputData);
|
||
|
toastr()->success('Product Created Succesfully');
|
||
|
|
||
|
return redirect()->route('product.index');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the specified resource.
|
||
|
*/
|
||
|
public function show($id)
|
||
|
{
|
||
|
$data['title'] = 'Show Product';
|
||
|
$data['product'] = $this->productRepository->getProductById($id);
|
||
|
$data['status'] = Product::STATUS;
|
||
|
|
||
|
return view('product::product.show', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Show the form for editing the specified resource.
|
||
|
*/
|
||
|
public function edit($id)
|
||
|
{
|
||
|
$data['title'] = 'Show Product';
|
||
|
$data['category'] = $this->categoryRepository->pluck();
|
||
|
$data['subCategory'] = $this->subCategoryRepository->pluck();
|
||
|
$data['supplier'] = $this->supplierRepository->pluck();
|
||
|
$data['warehouse'] = $this->warehouseRepository->pluck();
|
||
|
$data['product'] = $this->productRepository->getProductById($id);
|
||
|
$data['status'] = Product::STATUS;
|
||
|
|
||
|
return view('product::product.edit', $data);
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Update the specified resource in storage.
|
||
|
*/
|
||
|
public function update(Request $request, $id): RedirectResponse
|
||
|
{
|
||
|
$inputData = $request->except(['_method', '_token']);
|
||
|
$this->productRepository->update($id, $inputData);
|
||
|
|
||
|
return redirect()->route('product.index');
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* Remove the specified resource from storage.
|
||
|
*/
|
||
|
public function destroy($id)
|
||
|
{
|
||
|
try {
|
||
|
$ProductModel = $this->productRepository->getProductById($id);
|
||
|
$ProductModel->delete();
|
||
|
|
||
|
toastr()->success('Product Delete Succesfully');
|
||
|
} catch (\Throwable $th) {
|
||
|
toastr()->error($th->getMessage());
|
||
|
}
|
||
|
|
||
|
return response()->json(['status' => true, 'message' => 'Product Delete Succesfully']);
|
||
|
}
|
||
|
}
|