| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146 |
- <?php
-
- namespace App\Http\Controllers;
-
- use App\Http\Requests\TopUp\StoreTopUpRequest;
- use App\Http\Requests\TopUp\UpdateTopUpRequest;
- use App\Models\Member;
- use App\Models\TopUp;
- use Inertia\Inertia;
-
- class TopUpController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Inertia\Response
- */
- public function index()
- {
- return inertia('topup/Index', [
- 'filters' => request()->all('startDate', 'endDate', 'search'),
- 'topUp' => TopUp::filter(request()->only('startDate', 'endDate', 'search'))
- ->latest()
- ->paginate(10)
- ->withQueryString()
- ->through(fn($topUp) => [
- 'id' => $topUp->id,
- 'updatedAt' => $topUp->updated_at,
- 'name' => $topUp->member->name,
- 'phone' => $topUp->member->phone,
- 'platNumber' => $topUp->member->vehicleDetail(),
- 'amount' => $topUp->amount,
- 'type' => $topUp->member->typeMember->type,
- 'expDate' => $topUp->exp_date,
- ]),
- ]);
- }
-
- /**
- * Show the form for creating a new resource.
- *
- * @return \Inertia\Response
- */
- public function create()
- {
- return inertia('topup/Create', [
- 'members' => Inertia::lazy(
- fn() => Member::filter(request()->only('search'))->latest()->get()->transform(fn($member) => [
- 'id' => $member->id,
- 'name' => $member->name,
- 'phone' => $member->phone,
- 'platNumber' => $member->vehicleDetail(),
- 'type' => $member->typeMember->type,
- 'expDate' => $member->exp_date,
- ])
- ),
- ]);
- }
-
- /**
- * Store a newly created resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @return \Illuminate\Http\Response
- */
- public function store(StoreTopUpRequest $request)
- {
- TopUp::create([
- 'balance' => $request->balance,
- 'exp_date' => $request->exp_date,
- 'member_id' => $request->member_id,
- 'user_id' => auth()->user()->id,
- ]);
-
- return back()->with('success', __('messages.success.store.top_up'));
- }
-
- /**
- * Display the specified resource.
- *
- * @param TopUp $topUp
- * @return \Inertia\Response
- */
- public function show(TopUp $topUp)
- {
- return inertia('topup/Show', [
- 'topUp' => [
- 'updatedAt' => $topUp->updated_at,
- 'name' => $topUp->member->name,
- 'phone' => $topUp->member->phone,
- 'platNumber' => $topUp->member->plat_number,
- 'balance' => $topUp->balance,
- 'expDate' => $topUp->exp_date,
- 'user' => [
- 'name' => $topUp->user->name,
- 'phone' => $topUp->user->phone,
- 'email' => $topUp->user->email,
- ],
- ],
- ]);
- }
-
- /**
- * Show the form for editing the specified resource.
- *
- * @param TopUp $topUp
- * @return \Inertia\Response
- */
- public function edit(TopUp $topUp)
- {
- return inertia('topup/Index', [
- 'topUp' => [
- 'balance' => $topUp->balance,
- 'exp_date' => $topUp->balance,
- ],
- ]);
- }
-
- /**
- * Update the specified resource in storage.
- *
- * @param \Illuminate\Http\Request $request
- * @param TopUp $topUp
- * @return \Illuminate\Http\Response
- */
- public function update(UpdateTopUpRequest $request, TopUp $topUp)
- {
- $topUp->update($request->validated());
-
- return back()->with('success', __('messages.success.update.top_up'));
- }
-
- /**
- * Remove the specified resource from storage.
- *
- * @param TopUp $topUp
- * @return \Illuminate\Http\Response
- */
- public function destroy(TopUp $topUp)
- {
- $topUp->delete();
-
- return to_route('users.index')->with('success', __('messages.success.destroy.top_up'));
- }
- }
|