Cleanup on schools
This commit is contained in:
parent
3f59e13ef7
commit
2033ac371b
|
|
@ -4,6 +4,7 @@ namespace App\Http\Controllers\Admin;
|
|||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Models\School;
|
||||
use App\Models\SchoolEmailDomain;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use function abort;
|
||||
|
|
@ -48,5 +49,55 @@ class SchoolController extends Controller
|
|||
return redirect('/admin/schools');
|
||||
}
|
||||
|
||||
public function create()
|
||||
{
|
||||
if (! Auth::user()->is_admin) abort(403);
|
||||
return view('admin.schools.create');
|
||||
}
|
||||
|
||||
public function store(Request $request)
|
||||
{
|
||||
request()->validate([
|
||||
'name' => ['required'],
|
||||
'address' => ['required'],
|
||||
'city' => ['required'],
|
||||
'state' => ['required'],
|
||||
'zip' => ['required'],
|
||||
]);
|
||||
|
||||
$school = School::create([
|
||||
'name' => request('name'),
|
||||
'address' => request('address'),
|
||||
'city' => request('city'),
|
||||
'state' => request('state'),
|
||||
'zip' => request('zip'),
|
||||
]);
|
||||
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);
|
||||
request()->validate([
|
||||
// validate that the combination of school and domain is unique on the school_email_domains table
|
||||
'domain' => ['required']
|
||||
]);
|
||||
SchoolEmailDomain::updateOrInsert([
|
||||
'school_id' => $school->id,
|
||||
'domain' => request('domain')],[]);
|
||||
|
||||
return redirect('/admin/schools/' . $school->id . '/edit')->with('success','Domain Added');
|
||||
|
||||
}
|
||||
|
||||
public function destroy_domain(Request $request, SchoolEmailDomain $domain)
|
||||
{
|
||||
// Destroy the $domain
|
||||
$domain->delete();
|
||||
|
||||
// return a redirect to the previous URL
|
||||
return redirect()->back();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -25,7 +25,7 @@
|
|||
@endforeach
|
||||
</x-form.select>
|
||||
</x-form.body-grid>
|
||||
<x-form.footer>
|
||||
<x-form.footer class="!py-5">
|
||||
<x-form.button>Edit Entry</x-form.button>
|
||||
</x-form.footer>
|
||||
</x-form.form>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
<x-layout.app>
|
||||
<x-card.card class="mx-auto max-w-lg">
|
||||
<x-card.heading class="">
|
||||
New School
|
||||
</x-card.heading>
|
||||
|
||||
|
||||
<x-form.form method="POST" action="/admin/schools" class="!mt-4">
|
||||
<x-form.body-grid columns="6" class="max-w-full">
|
||||
<x-form.field name="name" label_text="School Name" colspan="6"/>
|
||||
<x-form.field name="address" label_text="School Address" colspan="6"/>
|
||||
<x-form.field name="city" label_text="City" colspan="3"/>
|
||||
<x-form.field name="state" label_text="State" colspan="2"/>
|
||||
<x-form.field name="zip" label_text="Zip"/>
|
||||
</x-form.body-grid>
|
||||
<x-form.footer submit-button-text="Create School" class="mb-5"/>
|
||||
</x-form.form>
|
||||
</x-card.card>
|
||||
</x-layout.app>
|
||||
|
|
@ -1,19 +1,10 @@
|
|||
<x-layout.app>
|
||||
<x-card.card class="mx-auto max-w-xl">
|
||||
<x-card.heading>Edit School</x-card.heading>
|
||||
<x-form.form method="PATCH" action="/admin/schools/{{ $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>Update User</x-form.button>
|
||||
</x-form.footer>
|
||||
</x-form.form>
|
||||
</x-card.card>
|
||||
|
||||
<x-school.school-edit-form :form_action="'admin/schools/' . $school->id " :school="$school" />
|
||||
|
||||
<x-school.school-domain-form :school="$school" />
|
||||
|
||||
</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 --}}
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
</x-form.select>
|
||||
</x-form.body-grid>
|
||||
<x-form.footer>
|
||||
<x-form.footer class="py-5">
|
||||
<x-form.button>Update User</x-form.button>
|
||||
</x-form.footer>
|
||||
</x-form.form>
|
||||
|
|
|
|||
|
|
@ -0,0 +1,26 @@
|
|||
@props(['school'])
|
||||
<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,16 @@
|
|||
@props(['form_action','school'])
|
||||
<x-card.card class="mx-auto max-w-xl">
|
||||
<x-card.heading>Edit School</x-card.heading>
|
||||
<x-form.form method="PATCH" action="{{ $form_action }}">
|
||||
<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>
|
||||
|
|
@ -1,10 +1,11 @@
|
|||
<x-layout.app>
|
||||
|
||||
<x-card.card class="mx-auto max-w-lg">
|
||||
<x-card.heading>
|
||||
<x-card.heading class="">
|
||||
New School
|
||||
</x-card.heading>
|
||||
<x-form.form method="POST" action="/schools" class="-mt-5">
|
||||
|
||||
|
||||
<x-form.form method="POST" action="/schools" class="!mt-4">
|
||||
<x-form.body-grid columns="6" class="max-w-full">
|
||||
<x-form.field name="name" label_text="School Name" colspan="6"/>
|
||||
<x-form.field name="address" label_text="School Address" colspan="6"/>
|
||||
|
|
@ -12,45 +13,7 @@
|
|||
<x-form.field name="state" label_text="State" colspan="2"/>
|
||||
<x-form.field name="zip" label_text="Zip"/>
|
||||
</x-form.body-grid>
|
||||
<x-form.footer submit-button-text="Create School"/>
|
||||
<x-form.footer submit-button-text="Create School" class="mb-5"/>
|
||||
</x-form.form>
|
||||
</x-card.card>
|
||||
{{-- <x-slot:page_title>Create School</x-slot:page_title>--}}
|
||||
{{-- <div class="space-y-10 divide-y divide-gray-900/10">--}}
|
||||
{{-- <x-layout.page-section :first="true">--}}
|
||||
{{-- <x-slot:section_name>School Information</x-slot:section_name>--}}
|
||||
{{-- <x-form.form method="POST" action="/schools">--}}
|
||||
{{-- <x-form.body-grid columns="6" class="max-w-full">--}}
|
||||
{{-- <x-form.field name="name" label_text="School Name" colspan="6"/>--}}
|
||||
{{-- <x-form.field name="address" label_text="School Address" colspan="6"/>--}}
|
||||
{{-- <x-form.field name="city" label_text="City" colspan="3"/>--}}
|
||||
{{-- <x-form.field name="state" label_text="State" colspan="2"/>--}}
|
||||
{{-- <x-form.field name="zip" label_text="Zip"/>--}}
|
||||
{{-- </x-form.body-grid>--}}
|
||||
{{-- </x-form.form>--}}
|
||||
|
||||
{{-- </x-layout.page-section>--}}
|
||||
|
||||
|
||||
{{-- <x-layout.page-section--}}
|
||||
{{-- :first="true">--}}
|
||||
|
||||
{{-- <x-slot:section_name>School Information</x-slot:section_name>--}}
|
||||
|
||||
|
||||
{{-- <x-form.card--}}
|
||||
{{-- submit-button-text="Create School"--}}
|
||||
{{-- method="POST"--}}
|
||||
{{-- action="/schools"--}}
|
||||
{{-- cols="9"--}}
|
||||
{{-- >--}}
|
||||
{{-- <x-form.field name="name" label_text="School Name" div_classes="sm:col-span-6"/>--}}
|
||||
{{-- <x-form.field name="address" label_text="School Address" div_classes="sm:col-span-6"/>--}}
|
||||
{{-- <x-form.field name="city" label_text="City" div_classes="sm:col-span-3"/>--}}
|
||||
{{-- <x-form.field name="state" label_text="State" div_classes="sm:col-span-2"/>--}}
|
||||
{{-- <x-form.field name="zip" label_text="Zip" div_classes="sm:col-span-1"/>--}}
|
||||
{{-- </x-form.card>--}}
|
||||
|
||||
{{-- </x-layout.page-section>--}}
|
||||
{{-- </div>--}}
|
||||
</x-layout.app>
|
||||
|
|
|
|||
|
|
@ -1,22 +1,8 @@
|
|||
<x-layout.app>
|
||||
<div class="mx-auto max-w-lg">
|
||||
<x-card.card>
|
||||
<x-card.heading>
|
||||
Edit School
|
||||
</x-card.heading>
|
||||
|
||||
<x-form.form method="PATCH" action="/schools/{{ $school->id }}">
|
||||
<x-form.body-grid columns="7">
|
||||
<x-form.field name="name" type="text" colspan="7" label_text="School Name" value="{{ $school->name }}" />
|
||||
<x-form.field name="address" type="text" colspan="7" label_text="School Address" value="{{ $school->address }}" />
|
||||
<x-form.field name="city" type="text" colspan="4" label_text="City" value="{{ $school->city }}" />
|
||||
<x-form.field name="state" type="text" colspan="1" label_text="State" value="{{ $school->state }}" />
|
||||
<x-form.field name="zip" type="text" colspan="2" label_text="Zip" value="{{ $school->zip }}" />
|
||||
</x-form.body-grid>
|
||||
<x-form.footer submit-button-text="Edit School" />
|
||||
</x-form.form>
|
||||
</x-card.card>
|
||||
</div>
|
||||
<x-school.school-edit-form :form_action="'/schools/' . $school->id" :school="$school" />
|
||||
|
||||
|
||||
</x-layout.app>
|
||||
|
||||
{{--<x-layout.app>
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<x-layout.page-section-container>
|
||||
<x-layout.page-section>
|
||||
<x-slot:section_name>Add Student</x-slot:section_name>
|
||||
<x-form.form method="POST" action="/students">
|
||||
<x-form.form method="POST" action="/students" class="mb-6 mt-3">
|
||||
<x-form.body-grid columns="8" class="max-w-full">
|
||||
<x-form.field name="first_name" label_text="First Name" colspan="3"/>
|
||||
<x-form.field name="last_name" label_text="Last Name" colspan="3"/>
|
||||
|
|
|
|||
|
|
@ -95,9 +95,14 @@ Route::middleware(['auth','verified',CheckIfAdmin::class])->prefix('admin/')->gr
|
|||
|
||||
// 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');
|
||||
|
||||
});
|
||||
|
||||
// Admin User Routes
|
||||
|
|
|
|||
Loading…
Reference in New Issue