Heera/Modules/Estimate/app/Http/Controllers/EstimateDetailController.php
2024-05-16 09:31:08 +05:45

130 lines
3.5 KiB
PHP

<?php
namespace Modules\Estimate\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Customer\Repositories\CustomerInterface;
use Modules\Estimate\Models\EstimateDetail;
use Modules\Estimate\Repositories\EstimateDetailInterface;
class EstimateDetailController extends Controller
{
private $estimateDetailRepository;
private $customerRepository;
public function __construct(
EstimateDetailInterface $estimateDetailRepository,
CustomerInterface $customerRepository
) {
$this->estimateDetailRepository = $estimateDetailRepository;
$this->customerRepository = $customerRepository;
}
/**
* Display a listing of the resource.
*/
public function index()
{
$data['title'] = 'Estimate Detail List';
$data['estimateDetails'] = $this->estimateDetailRepository->findAll();
return view('estimate::estimateDetail.index', $data);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
$data['title'] = 'Create EstimateDetail';
$data['editable'] = false;
$data['customerList'] = $this->customerRepository->pluck();
return view('estimate::estimateDetail.create', $data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request): RedirectResponse
{
try {
$inputData = $request->all();
$this->estimateDetailRepository->create($inputData);
toastr()->success('EstimateDetail created succesfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return redirect()->route('estimateDetail.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
$data['title'] = 'Show EstimateDetail';
$data['estimateDetail'] = $this->estimateDetailRepository->getEstimateDetailById($id);
$data['customerList'] = $this->customerRepository->pluck();
return view('estimate::estimateDetail.show', $data);
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
$data['title'] = 'Edit EstimateDetail';
$data['editable'] = true;
$data['estimateDetail'] = $this->estimateDetailRepository->getEstimateDetailById($id);
return view('estimate::estimateDetail.edit', $data);
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
try {
$this->estimateDetailRepository->update($id, $inputData);
flash()->success('EstimateDetail updated succesfully');
} catch (\Throwable $th) {
flash()->error($th->getMessage());
}
return redirect()->route('EstimateDetail.index');
}
/**
* Remove the specified resource from storage.
*/
public function destroy($id)
{
try {
$EstimateDetailModel = $this->estimateDetailRepository->getEstimateDetailById($id);
$EstimateDetailModel->delete();
flash()->success('EstimateDetail deleted succesfully');
} catch (\Throwable $th) {
flash()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'EstimateDetail deleted succesfully']);
}
}