60 lines
1.7 KiB
PHP
60 lines
1.7 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
use App\Actions\Entries\CreateEntry;
|
|
use App\Http\Requests\EntryStoreRequest;
|
|
use App\Models\Audition;
|
|
use App\Models\Entry;
|
|
use Illuminate\Http\Request;
|
|
use Illuminate\Support\Facades\Auth;
|
|
|
|
use function abort;
|
|
|
|
class EntryController extends Controller
|
|
{
|
|
public function index()
|
|
{
|
|
if (! auth()->user()->school_id) {
|
|
abort(403);
|
|
}
|
|
|
|
$entries = Auth::user()->entries()
|
|
->select('entries.*')
|
|
->join('students as s', 's.id', '=', 'entries.student_id')
|
|
->join('auditions as a', 'a.id', '=', 'entries.audition_id')
|
|
->with(['student', 'audition'])
|
|
->orderBy('s.last_name')
|
|
->orderBy('s.first_name')
|
|
->orderBy('a.score_order')
|
|
->get();
|
|
$auditions = Audition::open()->get();
|
|
$students = Auth::user()->students;
|
|
$students->load('school');
|
|
|
|
return view('entries.index', ['entries' => $entries, 'students' => $students, 'auditions' => $auditions]);
|
|
}
|
|
|
|
public function store(EntryStoreRequest $request, CreateEntry $creator)
|
|
{
|
|
$validData = $request->validatedWithEnterFor();
|
|
|
|
$creator($validData['student_id'], $validData['audition_id'], $validData['enter_for'] ?? []);
|
|
|
|
return redirect()->route('entries.index')->with('success', 'The entry has been added.');
|
|
}
|
|
|
|
public function destroy(Request $request, Entry $entry)
|
|
{
|
|
if ($request->user()->cannot('delete', $entry)) {
|
|
abort(403);
|
|
}
|
|
|
|
$entry->delete();
|
|
|
|
return redirect()->route('entries.index')->with('success',
|
|
'The '.$entry->audition->name.'entry for '.$entry->student->full_name().'has been deleted.');
|
|
|
|
}
|
|
}
|