100 lines
2.8 KiB
PHP
100 lines
2.8 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers\admin;
|
|
|
|
use App\Http\Controllers\Controller;
|
|
use App\Http\Requests\PaymentRequest;
|
|
use App\Models\Payment;
|
|
use App\Repositories\Payment\PaymentReppositoryInterface;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\DB;
|
|
|
|
class PaymentController extends Controller
|
|
{
|
|
public function __construct(
|
|
public PaymentReppositoryInterface $paymentReppository
|
|
) {}
|
|
public function index(Request $request)
|
|
{
|
|
$payments = $this->paymentReppository->filter(
|
|
$request->merge(['page' => $request->get('page') ?? 1])->all()
|
|
);
|
|
$title = 'List Payment';
|
|
|
|
return view('admin.payment.index', compact('payments', 'title'));
|
|
}
|
|
|
|
public function create()
|
|
{
|
|
$title = 'Add new Payment Method';
|
|
|
|
return view('admin.payment.add', compact('title'));
|
|
}
|
|
|
|
public function store(PaymentRequest $request)
|
|
{
|
|
$request->validated();
|
|
|
|
DB::beginTransaction();
|
|
try {
|
|
$this->paymentReppository->create($request->all());
|
|
DB::commit();
|
|
} catch (\Exception $exception) {
|
|
DB::rollBack();
|
|
return back()->withErrors($exception->getMessage());
|
|
}
|
|
return redirect()->route('payment.index')->with('success', 'Added successfully');
|
|
}
|
|
|
|
public function edit(int $id = 0)
|
|
{
|
|
$payment = $this->paymentReppository->find($id);
|
|
|
|
if (! $payment) {
|
|
return back()->withErrors('Invalid request');
|
|
}
|
|
$title = 'Edit Payment Method';
|
|
|
|
return view('admin.payment.edit', compact('title', 'payment'));
|
|
}
|
|
public function update(int $id = 0, PaymentRequest $request)
|
|
{
|
|
$payment = $this->paymentReppository->find($id);
|
|
|
|
if (! $payment) {
|
|
return back()->withErrors('Invalid request');
|
|
}
|
|
$request->validated();
|
|
|
|
|
|
DB::beginTransaction();
|
|
try {
|
|
$this->paymentReppository->update($id, $request->all());
|
|
DB::commit();
|
|
} catch (\Exception $exception) {
|
|
DB::rollBack();
|
|
return back()->withErrors($exception->getMessage());
|
|
}
|
|
return redirect()->route('payment.index')->with('success', 'Updated successfully');
|
|
}
|
|
|
|
public function destroy(int $id = 0)
|
|
{
|
|
$payment = $this->paymentReppository->find($id);
|
|
|
|
if (! $payment) {
|
|
return back()->withErrors('Invalid request');
|
|
}
|
|
|
|
DB::beginTransaction();
|
|
try {
|
|
$this->paymentReppository->delete($id);
|
|
DB::commit();
|
|
} catch (\Exception $exception) {
|
|
DB::rollBack();
|
|
return back()->withErrors($exception->getMessage());
|
|
}
|
|
return redirect()->route('payment.index')->with('success', 'Deleted successfully');
|
|
}
|
|
}
|