Update school admin page
This commit is contained in:
parent
1a5efd8555
commit
9da091ba51
|
|
@ -7,6 +7,7 @@ use App\Models\School;
|
||||||
use App\Models\SchoolEmailDomain;
|
use App\Models\SchoolEmailDomain;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Illuminate\Support\Facades\Auth;
|
use Illuminate\Support\Facades\Auth;
|
||||||
|
|
||||||
use function abort;
|
use function abort;
|
||||||
use function redirect;
|
use function redirect;
|
||||||
use function request;
|
use function request;
|
||||||
|
|
@ -15,20 +16,37 @@ class SchoolController extends Controller
|
||||||
{
|
{
|
||||||
public function index()
|
public function index()
|
||||||
{
|
{
|
||||||
if (! Auth::user()->is_admin) abort(403);
|
if (! Auth::user()->is_admin) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
$schools = School::with(['users', 'students', 'entries'])->orderBy('name')->get();
|
$schools = School::with(['users', 'students', 'entries'])->orderBy('name')->get();
|
||||||
|
|
||||||
return view('admin.schools.index', ['schools' => $schools]);
|
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)
|
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]);
|
return view('admin.schools.edit', ['school' => $school]);
|
||||||
}
|
}
|
||||||
|
|
||||||
public function update(School $school)
|
public function update(School $school)
|
||||||
{
|
{
|
||||||
if (! Auth::user()->is_admin) abort(403);
|
if (! Auth::user()->is_admin) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
request()->validate([
|
request()->validate([
|
||||||
'name' => ['required'],
|
'name' => ['required'],
|
||||||
|
|
@ -46,12 +64,15 @@ class SchoolController extends Controller
|
||||||
'zip' => request('zip'),
|
'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()
|
public function create()
|
||||||
{
|
{
|
||||||
if (! Auth::user()->is_admin) abort(403);
|
if (! Auth::user()->is_admin) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
|
|
||||||
return view('admin.schools.create');
|
return view('admin.schools.create');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -72,15 +93,18 @@ class SchoolController extends Controller
|
||||||
'state' => request('state'),
|
'state' => request('state'),
|
||||||
'zip' => request('zip'),
|
'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)
|
public function add_domain(Request $request, School $school)
|
||||||
{
|
{
|
||||||
if (! Auth::user()->is_admin) abort(403);
|
if (! Auth::user()->is_admin) {
|
||||||
|
abort(403);
|
||||||
|
}
|
||||||
request()->validate([
|
request()->validate([
|
||||||
// validate that the combination of school and domain is unique on the school_email_domains table
|
// validate that the combination of school and domain is unique on the school_email_domains table
|
||||||
'domain' => ['required']
|
'domain' => ['required'],
|
||||||
]);
|
]);
|
||||||
SchoolEmailDomain::updateOrInsert([
|
SchoolEmailDomain::updateOrInsert([
|
||||||
'school_id' => $school->id,
|
'school_id' => $school->id,
|
||||||
|
|
@ -98,6 +122,4 @@ class SchoolController extends Controller
|
||||||
// return a redirect to the previous URL
|
// return a redirect to the previous URL
|
||||||
return redirect()->back();
|
return redirect()->back();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
namespace App\Observers;
|
namespace App\Observers;
|
||||||
|
|
||||||
use App\Events\AuditionChange;
|
|
||||||
use App\Events\EntryChange;
|
|
||||||
use App\Models\School;
|
use App\Models\School;
|
||||||
|
|
||||||
class SchoolObserver
|
class SchoolObserver
|
||||||
|
|
@ -21,8 +19,7 @@ class SchoolObserver
|
||||||
*/
|
*/
|
||||||
public function updated(School $school): void
|
public function updated(School $school): void
|
||||||
{
|
{
|
||||||
AuditionChange::dispatch();
|
|
||||||
EntryChange::dispatch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
@ -30,7 +27,6 @@ class SchoolObserver
|
||||||
*/
|
*/
|
||||||
public function deleted(School $school): void
|
public function deleted(School $school): void
|
||||||
{
|
{
|
||||||
AuditionChange::dispatch();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -5,6 +5,3 @@
|
||||||
<x-school.school-domain-form :school="$school" />
|
<x-school.school-domain-form :school="$school" />
|
||||||
|
|
||||||
</x-layout.app>
|
</x-layout.app>
|
||||||
|
|
||||||
{{--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 --}}
|
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
<x-table.body>
|
<x-table.body>
|
||||||
@foreach($schools as $school)
|
@foreach($schools as $school)
|
||||||
<tr>
|
<tr>
|
||||||
<x-table.td><a href="/admin/schools/{{ $school->id }}/edit">{{ $school->name }}</a></x-table.td>
|
<x-table.td><a href="/admin/schools/{{ $school->id }}">{{ $school->name }}</a></x-table.td>
|
||||||
<x-table.td>{{ $school->users->count() }}</x-table.td>
|
<x-table.td>{{ $school->users->count() }}</x-table.td>
|
||||||
<x-table.td>{{ $school->students->count() }}</x-table.td>
|
<x-table.td>{{ $school->students->count() }}</x-table.td>
|
||||||
<x-table.td>{{ $school->entries->count() }}</x-table.td>
|
<x-table.td>{{ $school->entries->count() }}</x-table.td>
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1,25 @@
|
||||||
|
<x-card.card class="mx-auto max-w-sm mt-8">
|
||||||
|
<x-card.heading>Associated Domains</x-card.heading>
|
||||||
|
<x-card.list.body>
|
||||||
|
@foreach($school->emailDomains as $domain)
|
||||||
|
<x-card.list.row class="!py-1.5 align-middle">
|
||||||
|
<form method="POST" action="/admin/schools/domain/{{ $domain->id }}" id="deleteDomain{{$domain->id}}">
|
||||||
|
@csrf
|
||||||
|
@method('DELETE')
|
||||||
|
<button type="submit">
|
||||||
|
<svg class="w-6 h-6 text-gray-800 dark:text-white" aria-hidden="true" xmlns="http://www.w3.org/2000/svg" width="24" height="24" fill="currentColor" viewBox="0 0 24 24">
|
||||||
|
<path fill-rule="evenodd" d="M2 12C2 6.477 6.477 2 12 2s10 4.477 10 10-4.477 10-10 10S2 17.523 2 12Zm7.707-3.707a1 1 0 0 0-1.414 1.414L10.586 12l-2.293 2.293a1 1 0 1 0 1.414 1.414L12 13.414l2.293 2.293a1 1 0 0 0 1.414-1.414L13.414 12l2.293-2.293a1 1 0 0 0-1.414-1.414L12 10.586 9.707 8.293Z" clip-rule="evenodd"/>
|
||||||
|
</svg>
|
||||||
|
|
||||||
|
</button><span class="px-3">{{ $domain->domain }}</span>
|
||||||
|
</form>
|
||||||
|
</x-card.list.row>
|
||||||
|
@endforeach
|
||||||
|
<x-card.list.row class="!py-1.5">
|
||||||
|
<form method="POST" action="/admin/schools/{{ $school->id }}/add_domain" class="grid sm:grid-cols-2 gap-4">
|
||||||
|
@csrf
|
||||||
|
<x-form.field name="domain" label_text="Add Domain" /><x-form.button class="sm:mt-6">Add Domain</x-form.button>
|
||||||
|
</form>
|
||||||
|
</x-card.list.row>
|
||||||
|
</x-card.list.body>
|
||||||
|
</x-card.card>
|
||||||
|
|
@ -0,0 +1,17 @@
|
||||||
|
<x-modal-body>
|
||||||
|
<x-card.card class="mx-auto max-w-xl">
|
||||||
|
<x-card.heading>Edit School Address</x-card.heading>
|
||||||
|
<x-form.form method="PATCH" action="{{ route('admin.schools.update',['school'=>$school->id]) }}">
|
||||||
|
<x-form.body-grid>
|
||||||
|
<x-form.field name="name" label_text="Name" colspan="6" value="{{ $school->name }}" />
|
||||||
|
<x-form.field name="address" label_text="Address" colspan="6" value="{{ $school->address }}" />
|
||||||
|
<x-form.field name="city" label_text="City" colspan="3" value="{{ $school->city }}" />
|
||||||
|
<x-form.field name="state" label_text="State" colspan="2" value="{{ $school->state }}" />
|
||||||
|
<x-form.field name="zip" label_text="Zip" colspan="1" value="{{ $school->zip }}" />
|
||||||
|
</x-form.body-grid>
|
||||||
|
<x-form.footer>
|
||||||
|
<x-form.button class="mb-5">Update School</x-form.button>
|
||||||
|
</x-form.footer>
|
||||||
|
</x-form.form>
|
||||||
|
</x-card.card>
|
||||||
|
</x-modal-body>
|
||||||
|
|
@ -0,0 +1,45 @@
|
||||||
|
<x-layout.app>
|
||||||
|
<x-slot:page_title>School: {{ $school->name }}</x-slot:page_title>
|
||||||
|
<div class="grid md:grid-cols-4 gap-3">
|
||||||
|
<div x-data="{ showModal: false }">
|
||||||
|
<x-card.card >
|
||||||
|
<x-card.heading >
|
||||||
|
<x-slot:right_side class="text-xs" >
|
||||||
|
<span @click="showModal = ! showModal">[ edit ]</span>
|
||||||
|
</x-slot:right_side>
|
||||||
|
Address
|
||||||
|
</x-card.heading>
|
||||||
|
<div class="ml-6 mb-3">
|
||||||
|
<p>{{ $school->name }}</p>
|
||||||
|
<p>{{ $school->address }}</p>
|
||||||
|
<p>{{ $school->city }}, {{ $school->state }} {{ $school->zip }}</p>
|
||||||
|
</div>
|
||||||
|
</x-card.card>
|
||||||
|
@include('admin.schools.show-domain-form')
|
||||||
|
@include('admin.schools.show-edit-address')
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="col-span-3">
|
||||||
|
<x-card.card class="px-5">
|
||||||
|
<x-card.heading>Directors</x-card.heading>
|
||||||
|
</x-card.card>
|
||||||
|
<div class="grid md:grid-cols-3 gap-3 mt-3">
|
||||||
|
@foreach($school->directors as $director)
|
||||||
|
<x-card.card>
|
||||||
|
<x-card.heading>{{ $director->full_name() }}</x-card.heading>
|
||||||
|
<div class="ml-6">
|
||||||
|
<p class="py-2">{{ $director->cell_phone }}</p>
|
||||||
|
<p class="py-2">
|
||||||
|
<a href="mailto:{{ $director->email }}">
|
||||||
|
{{ $director->email }}
|
||||||
|
</a>
|
||||||
|
</p>
|
||||||
|
<p class="pt-2">Judging Preference:</p>
|
||||||
|
<p class="pb-3">{{ $director->judging_preference }}</p>
|
||||||
|
</div>
|
||||||
|
</x-card.card>
|
||||||
|
@endforeach
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</x-layout.app>
|
||||||
|
|
@ -16,7 +16,9 @@
|
||||||
<x-layout.app>
|
<x-layout.app>
|
||||||
<x-slot:page_title>Test Page</x-slot:page_title>
|
<x-slot:page_title>Test Page</x-slot:page_title>
|
||||||
@php
|
@php
|
||||||
dump(Auth::user()->rooms->contains(1));
|
$schools = School::all();
|
||||||
|
|
||||||
|
}
|
||||||
@endphp
|
@endphp
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -93,13 +93,14 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
|
||||||
|
|
||||||
// Admin School Routes
|
// Admin School Routes
|
||||||
Route::prefix('schools')->controller(\App\Http\Controllers\Admin\SchoolController::class)->group(function () {
|
Route::prefix('schools')->controller(\App\Http\Controllers\Admin\SchoolController::class)->group(function () {
|
||||||
Route::post('/{school}/add_domain', 'add_domain');
|
Route::post('/{school}/add_domain', 'add_domain')->name('admin.schools.add_domain');
|
||||||
Route::get('/', 'index');
|
Route::get('/', 'index')->name('admin.schools.index');
|
||||||
Route::get('/create', 'create');
|
Route::get('/{school}', 'show')->name('admin.schools.show');
|
||||||
Route::get('/{school}/edit', 'edit');
|
Route::get('/create', 'create')->name('admin.schools.create');
|
||||||
Route::patch('/{school}', 'update');
|
Route::get('/{school}/edit', 'edit')->name('admin.schools.edit');
|
||||||
Route::post('/', 'store');
|
Route::patch('/{school}', 'update')->name('admin.schools.update');
|
||||||
Route::delete('/domain/{domain}', 'destroy_domain');
|
Route::post('/', 'store')->name('admin.schools.store');
|
||||||
|
Route::delete('/domain/{domain}', 'destroy_domain')->name('admin.schools.destroy_domain');
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue