%PDF- %PDF-
Direktori : /mnt/tnb2/git/loslex/app/Http/Controllers/ |
Current File : //mnt/tnb2/git/loslex/app/Http/Controllers/RegistrationController.php |
<?php namespace App\Http\Controllers; use Illuminate\View\View; use Illuminate\Support\Str; use App\Models\Registration; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; use Illuminate\Http\RedirectResponse; use App\Http\Requests\RegistrationUpdateRequest; class RegistrationController extends Controller { /* Store a newly created registration in storage. */ public function store(RegistrationUpdateRequest $request): RedirectResponse { // $regData = new Registration; $regData->fill($request->validated()); $regData->notcomp = $request->boolean('notcomp'); $regData->lexmember = $request->boolean('lexmember'); $regData->rookie = $request->boolean('rookie'); $regData->builder = $request->boolean('builder'); $regData->referee = $request->boolean('referee'); $regData->canceltoken = Str::orderedUuid(); $registration = $regData->save(); if ($request->has('lex_hash') && empty($regData->user->lex_hash)) { $user = $regData->user; $user->lex_hash = $request->input('lex_hash'); $user->save(); } return back(); } /* Display the specified registration. */ public function show(Registration $registration): View { return view('registration.show', [ 'registration' => $registration ]); } /* Show the form for editing the specified resource. */ public function edit(Registration $registration): View { return view('registration.edit', [ 'registration' => $registration, 'contest' => $registration->contest, // 'user' => Auth::user() ]); } /* Update the specified registration in storage. */ public function update(RegistrationUpdateRequest $request, Registration $registration): RedirectResponse { $registration->fill($request->validated()); $registration->notcomp = $request->boolean('notcomp'); $registration->lexmember = $request->boolean('lexmember'); $registration->rookie = $request->boolean('rookie'); $registration->builder = $request->boolean('builder'); $registration->referee = $request->boolean('referee'); $registration->save(); if ($request->has('lex_hash') && empty($registration->user->lex_hash)) { $user = $registration->user; $user->lex_hash = $request->input('lex_hash'); $user->save(); } return redirect(route('registration.show', $registration->id)); } /* Remove the specified registration from storage. */ public function destroy(Request $request, Registration $registration): RedirectResponse { $contestid = $registration->contest->id; if ($request->canceltoken == $registration->canceltoken) { $registration->delete(); } if ($request->has('maintain')) return back(); else return redirect(route('contest.show', $contestid)); } /* Switches single registration flags back and forth */ public function switch(Registration $registration, string $action): RedirectResponse { switch ($action) { case "paid": $registration->paid = !$registration->paid; break; case "present": $registration->present = !$registration->present; break; } $registration->save(); return back(); } }