2020-06-02 23:45:25 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Member;
|
|
|
|
|
2021-07-17 18:46:02 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
2022-05-01 21:00:15 +02:00
|
|
|
use App\Setting\NamiSettings;
|
2022-02-12 16:16:56 +01:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
2021-07-17 18:46:02 +02:00
|
|
|
use Illuminate\Http\Request;
|
2021-07-15 20:56:53 +02:00
|
|
|
use Inertia\Response;
|
2023-02-08 01:39:46 +01:00
|
|
|
use Zoomyboy\LaravelNami\Exceptions\ConflictException;
|
2023-09-05 16:29:22 +02:00
|
|
|
use Inertia;
|
2020-06-02 23:45:25 +02:00
|
|
|
|
|
|
|
class MemberController extends Controller
|
|
|
|
{
|
2023-09-05 16:29:22 +02:00
|
|
|
public function index(Request $request): Response
|
2022-03-11 20:19:17 +01:00
|
|
|
{
|
2021-04-11 01:25:40 +02:00
|
|
|
session()->put('menu', 'member');
|
|
|
|
session()->put('title', 'Mitglieder');
|
2023-05-02 23:49:16 +02:00
|
|
|
|
2023-09-05 16:29:22 +02:00
|
|
|
return Inertia::render('member/VIndex', [
|
2024-01-28 11:42:32 +01:00
|
|
|
'data' => MemberResource::collection(FilterScope::fromRequest($request->input('filter', ''))->getQuery()->query(
|
|
|
|
fn ($q) => $q
|
|
|
|
->select('*')
|
2023-10-31 10:38:32 +01:00
|
|
|
->with(['gender', 'subscription', 'leaderMemberships', 'ageGroupMemberships.subactivity'])
|
2023-08-14 23:57:15 +02:00
|
|
|
->withPendingPayment()
|
2023-05-02 23:49:16 +02:00
|
|
|
)->paginate(15)),
|
|
|
|
]);
|
2020-06-02 23:45:25 +02:00
|
|
|
}
|
2021-04-11 11:19:55 +02:00
|
|
|
|
2022-02-12 16:16:56 +01:00
|
|
|
public function create(): Response
|
|
|
|
{
|
2021-06-22 00:22:30 +02:00
|
|
|
session()->put('menu', 'member');
|
|
|
|
session()->put('title', 'Mitglied erstellen');
|
|
|
|
|
2024-08-27 23:20:34 +02:00
|
|
|
return Inertia::render('member/VForm', [
|
2023-09-07 16:33:40 +02:00
|
|
|
'data' => MemberResource::defaultModel(),
|
2021-06-22 00:22:30 +02:00
|
|
|
'mode' => 'create',
|
2023-05-02 23:13:00 +02:00
|
|
|
'meta' => MemberResource::meta(),
|
2021-06-22 00:22:30 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-05-01 21:00:15 +02:00
|
|
|
public function store(MemberRequest $request, NamiSettings $settings): RedirectResponse
|
2022-02-12 16:16:56 +01:00
|
|
|
{
|
2022-05-01 21:00:15 +02:00
|
|
|
$request->persistCreate($settings);
|
2021-06-22 00:22:30 +02:00
|
|
|
|
|
|
|
return redirect()->route('member.index');
|
|
|
|
}
|
|
|
|
|
2022-02-12 16:16:56 +01:00
|
|
|
public function edit(Member $member, Request $request): Response
|
|
|
|
{
|
2021-04-11 11:19:55 +02:00
|
|
|
session()->put('menu', 'member');
|
2021-06-28 23:15:16 +02:00
|
|
|
session()->put('title', "Mitglied {$member->firstname} {$member->lastname} bearbeiten");
|
2021-04-11 11:19:55 +02:00
|
|
|
|
2024-08-27 23:20:34 +02:00
|
|
|
return Inertia::render('member/VForm', [
|
2021-06-22 00:22:30 +02:00
|
|
|
'data' => new MemberResource($member),
|
|
|
|
'mode' => 'edit',
|
2022-04-29 00:23:28 +02:00
|
|
|
'conflict' => '1' === $request->query('conflict', '0'),
|
2023-05-02 23:13:00 +02:00
|
|
|
'meta' => MemberResource::meta(),
|
2021-04-11 11:19:55 +02:00
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2022-02-12 16:16:56 +01:00
|
|
|
public function update(Member $member, MemberRequest $request): RedirectResponse
|
|
|
|
{
|
2022-04-28 23:52:30 +02:00
|
|
|
try {
|
|
|
|
$request->persistUpdate($member);
|
2023-02-08 01:39:46 +01:00
|
|
|
} catch (ConflictException $e) {
|
|
|
|
return redirect()->route('member.edit', ['member' => $member, 'conflict' => '1']);
|
2022-04-28 23:52:30 +02:00
|
|
|
}
|
2021-04-11 11:19:55 +02:00
|
|
|
|
|
|
|
return redirect()->route('member.index');
|
|
|
|
}
|
2020-06-02 23:45:25 +02:00
|
|
|
}
|