StocksNew/Modules/Order/app/Http/Controllers/PaymentModeController.php
Sampanna Rimal afb2c202d6 changes
2024-09-11 12:32:15 +05:45

85 lines
2.5 KiB
PHP

<?php
namespace Modules\Order\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\Order\Models\PaymentMode;
use Modules\Order\Repositories\PaymentModeRepository;
class PaymentModeController extends Controller
{
private $paymentModeRepository;
public function __construct(PaymentModeRepository $paymentModeRepository)
{
$this->paymentModeRepository = $paymentModeRepository;
}
public function index()
{
$data['title'] = 'Payment Modes';
$data['paymentModes'] = $this->paymentModeRepository->findAll();
return view('order::paymentMode.index', $data);
}
public function create()
{
$data['title'] = 'Create Payment Mode';
$data['status'] = PaymentMode::STATUS;
return view('order::paymentMode.create', $data);
}
public function store(Request $request): RedirectResponse
{
$request->request->add(['slug' => slugify($request->title)]);
$inputData = $request->all();
$this->paymentModeRepository->create($inputData);
toastr()->success('Payment Mode Created Successfully');
return redirect()->route('paymentMode.index');
}
public function show($id)
{
$data['title'] = 'Show Payment Mode';
$data['status'] = PaymentMode::STATUS;
$data['paymentMode'] = $this->paymentModeRepository->getPaymentModeById($id);
return view('order::paymentMode.show', $data);
}
public function edit($id)
{
$data['title'] = 'Edit Payment Mode';
$data['status'] = PaymentMode::STATUS;
$data['paymentMode'] = $this->paymentModeRepository->getPaymentModeById($id);
return view('order::paymentMode.edit', $data);
}
public function update(Request $request, $id): RedirectResponse
{
$inputData = $request->except(['_method', '_token']);
$this->paymentModeRepository->update($id, $inputData);
return redirect()->route('paymentMode.index');
}
public function destroy($id)
{
try {
$stock = $this->paymentModeRepository->getPaymentModeById($id);
$stock->delete();
toastr()->success('Payment Mode Deleted Successfully');
} catch (\Throwable $th) {
toastr()->error($th->getMessage());
}
return response()->json(['status' => true, 'message' => 'Payment Mode Deleted Successfully']);
}
}