From 9f57c930fc9541e510f60ff9fa49eabcefb7b31e Mon Sep 17 00:00:00 2001 From: Matt Young Date: Fri, 31 May 2024 10:58:02 -0500 Subject: [PATCH] Adding entry complete --- app/Http/Controllers/EntryController.php | 23 ++++++++- app/Http/Controllers/StudentController.php | 4 +- app/Models/Entry.php | 1 + app/Policies/StudentPolicy.php | 13 ++--- .../views/components/form/select.blade.php | 37 ++++++++++++++ resources/views/entries/index.blade.php | 51 ++++++++++++------- .../student_audition_select_script.blade.php | 30 +++++++++++ resources/views/test.blade.php | 9 ++-- 8 files changed, 133 insertions(+), 35 deletions(-) create mode 100644 resources/views/components/form/select.blade.php create mode 100644 resources/views/students/student_audition_select_script.blade.php diff --git a/app/Http/Controllers/EntryController.php b/app/Http/Controllers/EntryController.php index 5ed88ea..cc2c9db 100644 --- a/app/Http/Controllers/EntryController.php +++ b/app/Http/Controllers/EntryController.php @@ -2,6 +2,8 @@ namespace App\Http\Controllers; +use App\Models\Audition; +use App\Models\Entry; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; @@ -11,6 +13,25 @@ class EntryController extends Controller public function index() { $entries = Auth::user()->entries()->with(['student','audition'])->get(); - return view('entries.index',['entries' => $entries]); + $auditions = Audition::all(); + $students = Auth::user()->students; + + return view('entries.index',['entries' => $entries, 'students' => $students, 'auditions' => $auditions]); + } + + public function store(Request $request) + { + // TODO write custom rule to verify the combination of student and audition is unique + $request->validate([ + 'student_id' => ['required', 'exists:students,id'], + 'audition_id' => ['required', 'exists:auditions,id'] + ]); + + $entry = Entry::create([ + 'student_id' => request('student_id'), + 'audition_id' => request('audition_id') + ]); + + return redirect('/entries'); } } diff --git a/app/Http/Controllers/StudentController.php b/app/Http/Controllers/StudentController.php index c7d05dd..b745f37 100644 --- a/app/Http/Controllers/StudentController.php +++ b/app/Http/Controllers/StudentController.php @@ -2,6 +2,7 @@ namespace App\Http\Controllers; +use App\Models\Audition; use App\Models\School; use App\Models\Student; use App\Models\User; @@ -20,7 +21,8 @@ class StudentController extends Controller public function index() { $students = Auth::user()->students()->with('entries')->get(); - return view('students.index',['students' => $students]); + $auditions = Audition::all(); + return view('students.index',['students' => $students, 'auditions' => $auditions]); } /** diff --git a/app/Models/Entry.php b/app/Models/Entry.php index a152d60..5c486ff 100644 --- a/app/Models/Entry.php +++ b/app/Models/Entry.php @@ -9,6 +9,7 @@ use Illuminate\Database\Eloquent\Relations\BelongsTo; class Entry extends Model { use HasFactory; + protected $guarded = []; public function student(): BelongsTo { diff --git a/app/Policies/StudentPolicy.php b/app/Policies/StudentPolicy.php index 781ef75..2e0fcf0 100644 --- a/app/Policies/StudentPolicy.php +++ b/app/Policies/StudentPolicy.php @@ -2,6 +2,7 @@ namespace App\Policies; +use App\Models\Entry; use App\Models\Student; use App\Models\User; use Illuminate\Auth\Access\Response; @@ -9,15 +10,6 @@ use function is_null; class StudentPolicy { - // TODO Blanket admin policy is not appropriate for students as it may break things in the audition process - /** - * Grant admin users access to all functions - */ - public function before(User $user, string $ability): bool|null - { - if($user->is_admin) return true; - return null; - } /** * Determine whether the user can view any models. */ @@ -39,6 +31,7 @@ class StudentPolicy */ public function create(User $user): bool { + if($user->is_admin) return true; return ! is_null($user->school_id); } @@ -47,6 +40,8 @@ class StudentPolicy */ public function update(User $user, Student $student): bool { + if (Entry::where('student_id','=',$student->id)->exists()) return false; // Don't allow deletion of a student with entries + if($user->is_admin) return true; return $user->school_id == $student->school_id; } diff --git a/resources/views/components/form/select.blade.php b/resources/views/components/form/select.blade.php new file mode 100644 index 0000000..41c581d --- /dev/null +++ b/resources/views/components/form/select.blade.php @@ -0,0 +1,37 @@ +@props([ + 'label' => false, + 'name', + 'colspan' => '1' +]) +@php + $colspan_classes = [ + '1' => '', + '2' => 'sm:col-span-2', + '3' => 'sm:col-span-3', + '4' => 'sm:col-span-4', + '5' => 'sm:col-span-5', + '6' => 'sm:col-span-6', + '7' => 'sm:col-span-7', + '8' => 'sm:col-span-8', + '9' => 'sm:col-span-9', + '10' => 'sm:col-span-10', + '11' => 'sm:col-span-11', + '12' => 'sm:col-span-12' + ]; + $label_attribs = [ + 'class' => 'block text-sm font-medium leading-6 text-gray-900', + 'for' => $name + ]; + $select_attribs = [ + 'class' => 'mt-2 block w-full rounded-md border-0 py-1.5 pl-3 pr-10 text-gray-900 ring-1 ring-inset ring-gray-300 focus:ring-2 focus:ring-indigo-600 sm:text-sm sm:leading-6', + 'id' => $name, + 'name' => $name +] +@endphp + +
1) class="{{ $colspan_classes["$colspan"] }}" @endif> + @if($label)@endif + +
diff --git a/resources/views/entries/index.blade.php b/resources/views/entries/index.blade.php index fba5a3d..007da63 100644 --- a/resources/views/entries/index.blade.php +++ b/resources/views/entries/index.blade.php @@ -9,13 +9,27 @@ Add Entry - - - - - - {{-- TODO make grade a dropdown --}} - Save + + + + + + Student + + + + + + Audition + + + + + Save @@ -41,19 +55,19 @@ {{ $entry->student->full_name(true) }} {{ $entry->student->grade }} {{ $entry->audition->name }} -{{-- --}} -{{-- Edit--}} -{{-- |--}} + {{-- --}} + {{-- Edit--}} + {{-- |--}} -{{--
--}} -{{-- @csrf--}} -{{-- @method('DELETE')--}} -{{-- Delete--}} -{{-- --}} + {{--
--}} + {{-- @csrf--}} + {{-- @method('DELETE')--}} + {{-- Delete--}} + {{-- --}} -{{--
--}} + {{--
--}} @endforeach @@ -61,4 +75,5 @@
+ @include('students.student_audition_select_script') diff --git a/resources/views/students/student_audition_select_script.blade.php b/resources/views/students/student_audition_select_script.blade.php new file mode 100644 index 0000000..331a0b7 --- /dev/null +++ b/resources/views/students/student_audition_select_script.blade.php @@ -0,0 +1,30 @@ + diff --git a/resources/views/test.blade.php b/resources/views/test.blade.php index c3fe94f..7f5060f 100644 --- a/resources/views/test.blade.php +++ b/resources/views/test.blade.php @@ -1,14 +1,11 @@ -@php use App\Models\School;use App\Models\SchoolEmailDomain;use App\Models\User;use Illuminate\Support\Facades\Auth; @endphp +@php use App\Models\Audition;use App\Models\School;use App\Models\SchoolEmailDomain;use App\Models\User;use Illuminate\Support\Facades\Auth; @endphp Test Page + @php - $entries = Auth::user()->entries()->with(['student','audition'])->get(); -// dd($entries->first()->student->full_name()) + @endphp - @foreach ($entries as $e) - {{ $e->student->full_name() }} is entered on {{ $e->audition->name }}
- @endforeach