diff --git a/app/Http/Controllers/Admin/SchoolController.php b/app/Http/Controllers/Admin/SchoolController.php index d0fad41..172b8b5 100644 --- a/app/Http/Controllers/Admin/SchoolController.php +++ b/app/Http/Controllers/Admin/SchoolController.php @@ -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(); + } + } diff --git a/resources/views/admin/entries/edit.blade.php b/resources/views/admin/entries/edit.blade.php index 112b2e0..9a863d1 100644 --- a/resources/views/admin/entries/edit.blade.php +++ b/resources/views/admin/entries/edit.blade.php @@ -25,7 +25,7 @@ @endforeach - + Edit Entry diff --git a/resources/views/admin/schools/create.blade.php b/resources/views/admin/schools/create.blade.php new file mode 100644 index 0000000..145406c --- /dev/null +++ b/resources/views/admin/schools/create.blade.php @@ -0,0 +1,19 @@ + + + + New School + + + + + + + + + + + + + + + diff --git a/resources/views/admin/schools/edit.blade.php b/resources/views/admin/schools/edit.blade.php index 49798e9..aaaf4de 100644 --- a/resources/views/admin/schools/edit.blade.php +++ b/resources/views/admin/schools/edit.blade.php @@ -1,19 +1,10 @@ - - Edit School - - - - - - - - - - Update User - - - + + + + + {{--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/users/edit.blade.php b/resources/views/admin/users/edit.blade.php index 9d6f140..7dbd695 100644 --- a/resources/views/admin/users/edit.blade.php +++ b/resources/views/admin/users/edit.blade.php @@ -16,7 +16,7 @@ - + Update User diff --git a/resources/views/components/school/school-domain-form.blade.php b/resources/views/components/school/school-domain-form.blade.php new file mode 100644 index 0000000..c0f8fa3 --- /dev/null +++ b/resources/views/components/school/school-domain-form.blade.php @@ -0,0 +1,26 @@ +@props(['school']) + + Associated Domains + + @foreach($school->emailDomains as $domain) + +
+ @csrf + @method('DELETE') + {{ $domain->domain }} +
+
+ @endforeach + +
+ @csrf + Add Domain + +
+
+
diff --git a/resources/views/components/school/school-edit-form.blade.php b/resources/views/components/school/school-edit-form.blade.php new file mode 100644 index 0000000..95e8a58 --- /dev/null +++ b/resources/views/components/school/school-edit-form.blade.php @@ -0,0 +1,16 @@ +@props(['form_action','school']) + + Edit School + + + + + + + + + + Update School + + + diff --git a/resources/views/schools/create.blade.php b/resources/views/schools/create.blade.php index db0669a..6487e05 100644 --- a/resources/views/schools/create.blade.php +++ b/resources/views/schools/create.blade.php @@ -1,10 +1,11 @@ - - + New School - + + + @@ -12,45 +13,7 @@ - + -{{-- Create School--}} -{{--
--}} -{{-- --}} -{{-- School Information--}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} - -{{-- --}} - - -{{-- --}} - -{{-- School Information--}} - - -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} -{{-- --}} - -{{-- --}} -{{--
--}}
diff --git a/resources/views/schools/edit.blade.php b/resources/views/schools/edit.blade.php index 2502a2f..cf18cbf 100644 --- a/resources/views/schools/edit.blade.php +++ b/resources/views/schools/edit.blade.php @@ -1,22 +1,8 @@ -
- - - Edit School - - - - - - - - - - - - -
+ + +
{{-- diff --git a/resources/views/students/index.blade.php b/resources/views/students/index.blade.php index dd60e95..6442743 100644 --- a/resources/views/students/index.blade.php +++ b/resources/views/students/index.blade.php @@ -6,7 +6,7 @@ Add Student - + @@ -41,7 +41,7 @@ - + @foreach($students as $student) {{ $student->full_name(true) }} diff --git a/routes/web.php b/routes/web.php index 5640ef0..f1b60cc 100644 --- a/routes/web.php +++ b/routes/web.php @@ -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