Files
pbao9 17b02631e4 Refactor views to use new layout structure and update routes for administrator pages
- Changed view extends from "admin.main" to "administrator.layout.master" across multiple files.
- Updated route names in admin.php and administrator.php to reflect new structure for user, order, invoice, and other management functionalities.
- Adjusted view includes to point to the new directory structure for blocks and components.
- Ensured all permission checks remain intact while refactoring the views.
2026-02-02 10:31:11 +07:00

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('administrator.pages.payment.index', compact('payments', 'title'));
}
public function create()
{
$title = 'Add new Payment Method';
return view('administrator.pages.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('administrator.pages.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');
}
}