restaurant changes
This commit is contained in:
111
Modules/Ingredient/app/Http/Controllers/UnitController.php
Normal file
111
Modules/Ingredient/app/Http/Controllers/UnitController.php
Normal file
@@ -0,0 +1,111 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Ingredient\Http\Controllers;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Modules\Ingredient\Models\Unit;
|
||||
use Modules\Ingredient\Repositories\UnitRepository;
|
||||
|
||||
class UnitController extends Controller
|
||||
{
|
||||
private $unitRepository;
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*/
|
||||
public function __construct(
|
||||
UnitRepository $unitRepository)
|
||||
{
|
||||
$this->unitRepository = $unitRepository;
|
||||
}
|
||||
|
||||
public function index()
|
||||
{
|
||||
$data['title'] = 'Unit List';
|
||||
$data['units'] = $this->unitRepository->findAll();
|
||||
|
||||
return view('ingredient::unit.index', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
$data['title'] = 'Create Unit';
|
||||
$data['status'] = Unit::STATUS;
|
||||
|
||||
return view('ingredient::unit.create', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*/
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
|
||||
$request->request->add(['slug' => slugify($request->title)]);
|
||||
$inputData = $request->all();
|
||||
$this->unitRepository->create($inputData);
|
||||
toastr()->success('Unit Created Succesfully');
|
||||
|
||||
return redirect()->route('unit.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the specified resource.
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
$data['title'] = 'Show Fabric Category';
|
||||
$data['status'] = Unit::STATUS;
|
||||
$data['unit'] = $this->unitRepository->getUnitById($id);
|
||||
|
||||
return view('ingredient::unit.show', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
$data['title'] = 'Edit Fabric Category';
|
||||
$data['status'] = Unit::STATUS;
|
||||
$data['unit'] = $this->unitRepository->getUnitById($id);
|
||||
|
||||
return view('ingredient::unit.edit', $data);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*/
|
||||
public function update(Request $request, $id): RedirectResponse
|
||||
{
|
||||
$inputData = $request->except(['_method', '_token']);
|
||||
$this->unitRepository->update($id, $inputData);
|
||||
|
||||
return redirect()->route('unit.index');
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
try {
|
||||
$UnitModel = $this->unitRepository->getUnitById($id);
|
||||
$UnitModel->delete();
|
||||
|
||||
toastr()->success('Fabric Category Delete Succesfully');
|
||||
} catch (\Throwable $th) {
|
||||
toastr()->error($th->getMessage());
|
||||
}
|
||||
|
||||
return response()->json(['status' => true, 'message' => 'Fabric Category Delete Succesfully']);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user