Show an error when an administrator attempts to duplicate an existing entry.
This commit is contained in:
parent
a5f11fb897
commit
550614a317
|
|
@ -3,6 +3,8 @@
|
||||||
namespace App\Http\Requests;
|
namespace App\Http\Requests;
|
||||||
|
|
||||||
use App\Models\Audition;
|
use App\Models\Audition;
|
||||||
|
use App\Models\Entry;
|
||||||
|
use App\Models\Student;
|
||||||
use Auth;
|
use Auth;
|
||||||
use Carbon\Carbon;
|
use Carbon\Carbon;
|
||||||
use Illuminate\Foundation\Http\FormRequest;
|
use Illuminate\Foundation\Http\FormRequest;
|
||||||
|
|
@ -44,6 +46,7 @@ class EntryStoreRequest extends FormRequest
|
||||||
$validator->after(function ($validator) {
|
$validator->after(function ($validator) {
|
||||||
$auditionId = $this->input('audition_id');
|
$auditionId = $this->input('audition_id');
|
||||||
$audition = Audition::find($auditionId);
|
$audition = Audition::find($auditionId);
|
||||||
|
$student = Student::find($this->input('student_id'));
|
||||||
|
|
||||||
if (! $audition) {
|
if (! $audition) {
|
||||||
$validator->errors()->add('audition_id', 'The selected audition does not exist.');
|
$validator->errors()->add('audition_id', 'The selected audition does not exist.');
|
||||||
|
|
@ -51,6 +54,11 @@ class EntryStoreRequest extends FormRequest
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (Entry::where('student_id', $this->input('student_id'))->where('audition_id', $auditionId)->exists()) {
|
||||||
|
$validator->errors()->add('student_id',
|
||||||
|
$student->full_name().' is already entered in the '.$audition->name.' audition.');
|
||||||
|
}
|
||||||
|
|
||||||
if (! Auth::user()->is_admin) { //Admins don't care about deadlines
|
if (! Auth::user()->is_admin) { //Admins don't care about deadlines
|
||||||
$currentDate = Carbon::now('America/Chicago')->format('Y-m-d');
|
$currentDate = Carbon::now('America/Chicago')->format('Y-m-d');
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -2,9 +2,20 @@
|
||||||
<x-layout.app>
|
<x-layout.app>
|
||||||
<x-card.card class="mx-auto max-w-2xl">
|
<x-card.card class="mx-auto max-w-2xl">
|
||||||
<x-card.heading>Create Entry</x-card.heading>
|
<x-card.heading>Create Entry</x-card.heading>
|
||||||
<x-form.form id='createEntryForm' method="POST" action="/admin/entries">
|
@if ($errors->any())
|
||||||
|
<div class="mt-3">
|
||||||
|
@foreach($errors->all() as $error)
|
||||||
|
<div class="ml-3">
|
||||||
|
<span
|
||||||
|
class="inline-flex items-center rounded-md bg-red-50 px-2 py-1 text-xs font-medium text-red-700 inset-ring inset-ring-red-600/10 dark:bg-red-400/10 dark:text-red-400 dark:inset-ring-red-400/20">{{$error}}</span>
|
||||||
|
</div>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
@endif
|
||||||
|
<x-form.form id='createEntryForm' method="POST" action="/admin/entries" class="mt-3">
|
||||||
<x-form.body-grid columns="3" x-data="studentAuditionFilter()">
|
<x-form.body-grid columns="3" x-data="studentAuditionFilter()">
|
||||||
|
|
||||||
|
|
||||||
<x-form.select name="student_id" colspan="2" x-model="selectedStudentId" @change="filterAuditions">
|
<x-form.select name="student_id" colspan="2" x-model="selectedStudentId" @change="filterAuditions">
|
||||||
<x-slot:label>Student</x-slot:label>
|
<x-slot:label>Student</x-slot:label>
|
||||||
<option value="" disabled selected>Select a student</option>
|
<option value="" disabled selected>Select a student</option>
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue