2021-08-22 22:23:17 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Membership;
|
|
|
|
|
2021-08-22 22:53:43 +02:00
|
|
|
use App\Activity;
|
2021-08-22 22:23:17 +02:00
|
|
|
use App\Http\Controllers\Controller;
|
|
|
|
use App\Member\Member;
|
2021-08-22 23:32:54 +02:00
|
|
|
use App\Member\Membership;
|
2021-08-22 22:53:43 +02:00
|
|
|
use App\Subactivity;
|
2021-08-22 22:23:17 +02:00
|
|
|
use Illuminate\Http\RedirectResponse;
|
|
|
|
use Illuminate\Http\Request;
|
|
|
|
|
|
|
|
class MembershipController extends Controller
|
|
|
|
{
|
2021-08-22 23:32:54 +02:00
|
|
|
|
2021-08-22 22:23:17 +02:00
|
|
|
public function store(Member $member, Request $request): RedirectResponse
|
|
|
|
{
|
2021-08-22 22:53:43 +02:00
|
|
|
$namiId = auth()->user()->api()->group($member->group->nami_id)->member($member->nami_id)
|
|
|
|
->putMembership([
|
2021-08-22 23:32:54 +02:00
|
|
|
'starts_at' => now(),
|
2021-08-22 22:53:43 +02:00
|
|
|
'group_id' => $member->group->nami_id,
|
|
|
|
'activity_id' => Activity::find($request->input('activity_id'))->nami_id,
|
|
|
|
'subactivity_id' => optional(Subactivity::find($request->input('subactivity_id')))->nami_id,
|
|
|
|
]);
|
|
|
|
|
2021-08-22 23:32:54 +02:00
|
|
|
$member->memberships()->create(array_merge(
|
2021-08-22 22:53:43 +02:00
|
|
|
$request->input(),
|
|
|
|
['nami_id' => $namiId],
|
|
|
|
));
|
2021-08-22 22:23:17 +02:00
|
|
|
|
2021-10-29 19:34:50 +02:00
|
|
|
$member->syncVersion(auth()->user()->api());
|
|
|
|
|
2021-08-22 22:23:17 +02:00
|
|
|
return redirect()->back();
|
|
|
|
}
|
2021-08-22 23:32:54 +02:00
|
|
|
|
|
|
|
public function destroy(Member $member, Membership $membership): RedirectResponse
|
|
|
|
{
|
|
|
|
auth()->user()->api()->group($member->group->nami_id)->member($member->nami_id)
|
|
|
|
->deleteMembership($membership->nami_id);
|
|
|
|
|
|
|
|
$membership->delete();
|
2021-10-29 19:34:50 +02:00
|
|
|
$member->syncVersion(auth()->user()->api());
|
2021-08-22 23:32:54 +02:00
|
|
|
|
|
|
|
return redirect()->back();
|
|
|
|
}
|
|
|
|
|
2021-08-22 22:23:17 +02:00
|
|
|
}
|