diff --git a/app/Http/Controllers/Admin/SchoolController.php b/app/Http/Controllers/Admin/SchoolController.php index 172b8b5..d34e7d7 100644 --- a/app/Http/Controllers/Admin/SchoolController.php +++ b/app/Http/Controllers/Admin/SchoolController.php @@ -7,6 +7,7 @@ use App\Models\School; use App\Models\SchoolEmailDomain; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; + use function abort; use function redirect; use function request; @@ -15,20 +16,37 @@ class SchoolController extends Controller { public function index() { - if (! Auth::user()->is_admin) abort(403); - $schools = School::with(['users','students','entries'])->orderBy('name')->get(); + if (! Auth::user()->is_admin) { + abort(403); + } + $schools = School::with(['users', 'students', 'entries'])->orderBy('name')->get(); + return view('admin.schools.index', ['schools' => $schools]); } + public function show(Request $request, School $school) + { + if (! Auth::user()->is_admin) { + abort(403); + } + + return view('admin.schools.show', ['school' => $school]); + } + public function edit(School $school) { - if (! Auth::user()->is_admin) abort(403); + if (! Auth::user()->is_admin) { + abort(403); + } + return view('admin.schools.edit', ['school' => $school]); } public function update(School $school) { - if (! Auth::user()->is_admin) abort(403); + if (! Auth::user()->is_admin) { + abort(403); + } request()->validate([ 'name' => ['required'], @@ -46,12 +64,15 @@ class SchoolController extends Controller 'zip' => request('zip'), ]); - return redirect('/admin/schools'); + return redirect()->route('admin.schools.show', ['school' => $school->id])->with('success', 'School '.$school->name.' updated'); } public function create() { - if (! Auth::user()->is_admin) abort(403); + if (! Auth::user()->is_admin) { + abort(403); + } + return view('admin.schools.create'); } @@ -72,21 +93,24 @@ class SchoolController extends Controller 'state' => request('state'), 'zip' => request('zip'), ]); - return redirect('/admin/schools')->with('success','School ' . $school->name . ' created'); + + return redirect('/admin/schools')->with('success', 'School '.$school->name.' created'); } public function add_domain(Request $request, School $school) { - if (! Auth::user()->is_admin) abort(403); + if (! Auth::user()->is_admin) { + abort(403); + } request()->validate([ // validate that the combination of school and domain is unique on the school_email_domains table - 'domain' => ['required'] + 'domain' => ['required'], ]); SchoolEmailDomain::updateOrInsert([ 'school_id' => $school->id, - 'domain' => request('domain')],[]); + 'domain' => request('domain')], []); - return redirect('/admin/schools/' . $school->id . '/edit')->with('success','Domain Added'); + return redirect('/admin/schools/'.$school->id.'/edit')->with('success', 'Domain Added'); } @@ -98,6 +122,4 @@ class SchoolController extends Controller // return a redirect to the previous URL return redirect()->back(); } - - } diff --git a/app/Observers/SchoolObserver.php b/app/Observers/SchoolObserver.php index a4b7ff0..419083d 100644 --- a/app/Observers/SchoolObserver.php +++ b/app/Observers/SchoolObserver.php @@ -2,8 +2,6 @@ namespace App\Observers; -use App\Events\AuditionChange; -use App\Events\EntryChange; use App\Models\School; class SchoolObserver @@ -21,8 +19,7 @@ class SchoolObserver */ public function updated(School $school): void { - AuditionChange::dispatch(); - EntryChange::dispatch(); + } /** @@ -30,7 +27,6 @@ class SchoolObserver */ public function deleted(School $school): void { - AuditionChange::dispatch(); } /** diff --git a/resources/views/admin/schools/edit.blade.php b/resources/views/admin/schools/edit.blade.php index aaaf4de..cb3fe60 100644 --- a/resources/views/admin/schools/edit.blade.php +++ b/resources/views/admin/schools/edit.blade.php @@ -5,6 +5,3 @@ - -{{--TODO Show directors on school page--}} -{{--TODO make this a component in the main schoosl page and have a prop to set the form action since that's the only difference --}} diff --git a/resources/views/admin/schools/index.blade.php b/resources/views/admin/schools/index.blade.php index 98b54db..c674387 100644 --- a/resources/views/admin/schools/index.blade.php +++ b/resources/views/admin/schools/index.blade.php @@ -21,7 +21,7 @@ @foreach($schools as $school) - {{ $school->name }} + {{ $school->name }} {{ $school->users->count() }} {{ $school->students->count() }} {{ $school->entries->count() }} diff --git a/resources/views/admin/schools/show-domain-form.blade.php b/resources/views/admin/schools/show-domain-form.blade.php new file mode 100644 index 0000000..f62c928 --- /dev/null +++ b/resources/views/admin/schools/show-domain-form.blade.php @@ -0,0 +1,25 @@ + + Associated Domains + + @foreach($school->emailDomains as $domain) + +
+ @csrf + @method('DELETE') + {{ $domain->domain }} +
+
+ @endforeach + +
+ @csrf + Add Domain + +
+
+
diff --git a/resources/views/admin/schools/show-edit-address.blade.php b/resources/views/admin/schools/show-edit-address.blade.php new file mode 100644 index 0000000..ab34b76 --- /dev/null +++ b/resources/views/admin/schools/show-edit-address.blade.php @@ -0,0 +1,17 @@ + + + Edit School Address + + + + + + + + + + Update School + + + + diff --git a/resources/views/admin/schools/show.blade.php b/resources/views/admin/schools/show.blade.php new file mode 100644 index 0000000..669d2f4 --- /dev/null +++ b/resources/views/admin/schools/show.blade.php @@ -0,0 +1,45 @@ + + School: {{ $school->name }} +
+
+ + + + [ edit ] + + Address + +
+

{{ $school->name }}

+

{{ $school->address }}

+

{{ $school->city }}, {{ $school->state }} {{ $school->zip }}

+
+
+ @include('admin.schools.show-domain-form') + @include('admin.schools.show-edit-address') +
+ +
+ + Directors + +
+ @foreach($school->directors as $director) + + {{ $director->full_name() }} +
+

{{ $director->cell_phone }}

+

+ + {{ $director->email }} + +

+

Judging Preference:

+

{{ $director->judging_preference }}

+
+
+ @endforeach +
+
+
+
diff --git a/resources/views/test.blade.php b/resources/views/test.blade.php index f36233e..8b6c30e 100644 --- a/resources/views/test.blade.php +++ b/resources/views/test.blade.php @@ -16,7 +16,9 @@ Test Page @php - dump(Auth::user()->rooms->contains(1)); + $schools = School::all(); + + } @endphp diff --git a/routes/admin.php b/routes/admin.php index 06a84f6..6b58ed4 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -93,13 +93,14 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')-> // Admin School Routes Route::prefix('schools')->controller(\App\Http\Controllers\Admin\SchoolController::class)->group(function () { - Route::post('/{school}/add_domain', 'add_domain'); - Route::get('/', 'index'); - Route::get('/create', 'create'); - Route::get('/{school}/edit', 'edit'); - Route::patch('/{school}', 'update'); - Route::post('/', 'store'); - Route::delete('/domain/{domain}', 'destroy_domain'); + Route::post('/{school}/add_domain', 'add_domain')->name('admin.schools.add_domain'); + Route::get('/', 'index')->name('admin.schools.index'); + Route::get('/{school}', 'show')->name('admin.schools.show'); + Route::get('/create', 'create')->name('admin.schools.create'); + Route::get('/{school}/edit', 'edit')->name('admin.schools.edit'); + Route::patch('/{school}', 'update')->name('admin.schools.update'); + Route::post('/', 'store')->name('admin.schools.store'); + Route::delete('/domain/{domain}', 'destroy_domain')->name('admin.schools.destroy_domain'); });