StocksNew/Modules/Product/app/Http/Controllers/WarehouseController.php

104 lines
2.8 KiB
PHP
Raw Normal View History

2024-08-27 12:03:06 +00:00
<?php
namespace Modules\Product\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Product\Models\Warehouse;
use Modules\Product\Repositories\WarehouseRepository;
class WarehouseController extends Controller
{
private $warehouseRepository;
/**
* Display a listing of the resource.
*/
public function __construct(WarehouseRepository $warehouseRepository)
{
$this->warehouseRepository = $warehouseRepository;
}
public function index()
{
$data['title'] = 'WareHouse List';
$data['warehouses'] = $this->warehouseRepository->findAll();
return view('product::warehouse.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create Warehouse';
$data['status'] = Warehouse::STATUS;
return view('product::warehouse.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
$inputData = $request->all();
$this->warehouseRepository->create($inputData);
toastr()->success('Warehouse Created Succesfully');
return redirect()->route('warehouse.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show Warehouse';
$data['warehouse'] = $this->warehouseRepository->getWarehouseById($id);
$data['status'] = Warehouse::STATUS;
return view('product::warehouse.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit Category';
$data['warehouse'] = $this->warehouseRepository->getWarehouseById($id);
$data['status'] = Warehouse::STATUS;
return view('product::warehouse.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$this->warehouseRepository->update($id, $inputData);
return redirect()->route('warehouse.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$WarehouseModel = $this->warehouseRepository->getWarehouseById($id);
$WarehouseModel->delete();
toastr()->success('Warehouse Delete Succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Warehouse Delete Succesfully']);
}
}