%PDF- %PDF-
Mini Shell

Mini Shell

Direktori : /www/loslex/demo/app/Http/Controllers/
Upload File :
Create Path :
Current File : //www/loslex/demo/app/Http/Controllers/OrganizerGroupController.php

<?php

namespace App\Http\Controllers;

use App\Models\OrganizerGroup;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Log;
use Illuminate\View\View;

class OrganizerGroupController extends Controller
{
    /* Display a listing of the resource. */
    public function index() : View
    {
        return view('organizers.list', [
            'groups' => OrganizerGroup::orderBy('name')->with(['users','contests'])->get(),
        ]);
    }

    /* Store a newly created resource in storage. */
    public function store(Request $request) : RedirectResponse
    {
        $request->validateWithBag('addOrgGroup', ['name' => 'required|string|max:255']);
        $orgGroup = OrganizerGroup::create(['name' => $request->name]);

        Log::info("Admin " . Auth::user()->username . " created new organizer group {$request->name}", [
            'admin' => Auth::user()->id,
            'group' => $orgGroup->id,
        ]);

        return redirect(route('organizer.show', $orgGroup->id));
    }

    /* Display the specified resource. */
    public function show(OrganizerGroup $organizer) : View
    {
        // Userlist displays only users not already being members of the group
        $groupmembers = OrganizerGroup::where('id', $organizer->id)->first()->users->pluck('id')->toArray();
        $userlist = User::whereNotIn('id', $groupmembers)->get();
        $userlist = $userlist->sortBy(fn ($usr) => $usr->displayname);

        return view('organizers.show', [
            'group' => $organizer,
            'users' => $userlist
        ]);
    }

    /* Show the form for editing the specified resource. */
    public function edit(OrganizerGroup $organizer)
    {
        // dd($organizer);
    }

    /* Update the specified resource in storage. */
    public function update(Request $request, OrganizerGroup $organizer)
    {
        //
    }

    /* Remove the specified resource from storage. */
    public function destroy(OrganizerGroup $organizer)
    {
        //
    }
}

Zerion Mini Shell 1.0