adrema/app/Member/MemberController.php

84 lines
3.0 KiB
PHP
Raw Normal View History

2020-06-02 23:45:25 +02:00
<?php
namespace App\Member;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
2021-04-11 11:19:55 +02:00
use App\Gender;
use App\Fee;
2021-04-11 11:44:51 +02:00
use App\Region;
use App\Country;
use App\Nationality;
use App\Confession;
2021-04-11 18:17:40 +02:00
use App\Bill\BillKind;
2021-06-23 01:05:17 +02:00
use App\Activity;
use App\Group;
2020-06-02 23:45:25 +02:00
class MemberController extends Controller
{
2021-04-11 20:01:37 +02:00
2020-06-02 23:45:25 +02:00
public function index(Request $request) {
2021-04-11 01:25:40 +02:00
session()->put('menu', 'member');
session()->put('title', 'Mitglieder');
return \Inertia::render('member/Index', [
2021-06-22 00:14:34 +02:00
'data' => MemberResource::collection(Member::search($request->query('search', null))->with('billKind')->paginate(15)),
'toolbar' => [ ['href' => route('member.create'), 'label' => 'Mitglied anlegen', 'color' => 'primary', 'icon' => 'plus'] ],
2020-06-02 23:45:25 +02:00
]);
}
2021-04-11 11:19:55 +02:00
2021-06-22 00:22:30 +02:00
public function create() {
session()->put('menu', 'member');
session()->put('title', 'Mitglied erstellen');
2021-06-23 01:05:17 +02:00
$activities = Activity::with('subactivities')->get();
2021-06-22 00:22:30 +02:00
return \Inertia::render('member/Form', [
2021-06-23 01:05:17 +02:00
'activities' => $activities->pluck('name', 'id'),
'subactivities' => $activities->map(function($activity) {
return ['subactivities' => $activity->subactivities->pluck('name', 'id'), 'id' => $activity->id];
})->pluck('subactivities', 'id'),
2021-06-22 00:22:30 +02:00
'billKinds' => BillKind::get()->pluck('name', 'id'),
'genders' => Gender::get()->pluck('name', 'id'),
'countries' => Country::get()->pluck('name', 'id'),
'regions' => Region::where('is_null', false)->get()->pluck('name', 'id'),
'nationalities' => Nationality::get()->pluck('name', 'id'),
'confessions' => Confession::where('is_null', false)->get()->pluck('name', 'id'),
'fees' => Fee::get()->pluck('name', 'id'),
2021-06-22 23:00:27 +02:00
'data' => [
'country_id' => Country::default()
],
2021-06-22 00:22:30 +02:00
'mode' => 'create',
]);
}
public function store(MemberRequest $request) {
$request->persistCreate();
return redirect()->route('member.index');
}
2021-04-11 11:19:55 +02:00
public function edit(Member $member, Request $request) {
session()->put('menu', 'member');
session()->put('title', 'Mitglied bearbeiten');
2021-06-22 00:22:30 +02:00
return \Inertia::render('member/Form', [
2021-04-11 18:17:40 +02:00
'billKinds' => BillKind::get()->pluck('name', 'id'),
2021-04-11 17:02:49 +02:00
'genders' => Gender::get()->pluck('name', 'id'),
2021-04-11 11:44:51 +02:00
'countries' => Country::get()->pluck('name', 'id'),
'regions' => Region::where('is_null', false)->get()->pluck('name', 'id'),
'nationalities' => Nationality::get()->pluck('name', 'id'),
'confessions' => Confession::where('is_null', false)->get()->pluck('name', 'id'),
2021-04-11 11:19:55 +02:00
'fees' => Fee::get()->pluck('name', 'id'),
2021-06-22 00:22:30 +02:00
'data' => new MemberResource($member),
'mode' => 'edit',
2021-04-11 11:19:55 +02:00
]);
}
2021-04-11 20:01:37 +02:00
public function update(Member $member, MemberRequest $request) {
$request->persistUpdate($member);
2021-04-11 11:19:55 +02:00
return redirect()->route('member.index');
}
2020-06-02 23:45:25 +02:00
}