Bug Kill
This commit is contained in:
parent
718ff6b7ab
commit
a9cb8ca584
|
|
@ -4,12 +4,11 @@ namespace App\Http\Controllers;
|
|||
|
||||
use App\Models\School;
|
||||
use App\Models\SchoolEmailDomain;
|
||||
use Illuminate\Auth\Access\Gate;
|
||||
use Illuminate\Http\RedirectResponse;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
|
||||
use function abort;
|
||||
use function dd;
|
||||
use function redirect;
|
||||
use function request;
|
||||
|
||||
|
|
@ -17,7 +16,9 @@ class SchoolController extends Controller
|
|||
{
|
||||
public function store(Request $request): RedirectResponse
|
||||
{
|
||||
if ($request->user()->cannot('create', School::class)) abort(403);
|
||||
if ($request->user()->cannot('create', School::class)) {
|
||||
abort(403);
|
||||
}
|
||||
request()->validate([
|
||||
'name' => ['required', 'min:3', 'max:30'],
|
||||
'address' => ['required'],
|
||||
|
|
@ -34,45 +35,52 @@ class SchoolController extends Controller
|
|||
'zip' => request('zip'),
|
||||
]);
|
||||
|
||||
// TODO allow for an audition administrator that is not connected to school and needs to create a school without associating with it
|
||||
|
||||
if (! Auth::user()->school) {
|
||||
Auth::user()->update([
|
||||
'school_id' => $school->id
|
||||
'school_id' => $school->id,
|
||||
]);
|
||||
|
||||
SchoolEmailDomain::create([
|
||||
'school_id' => $school->id,
|
||||
'domain' => Auth::user()->emailDomain()
|
||||
'domain' => Auth::user()->emailDomain(),
|
||||
]);
|
||||
}
|
||||
|
||||
|
||||
return redirect('/schools/'.$school->id);
|
||||
}
|
||||
|
||||
public function show(Request $request, School $school)
|
||||
{
|
||||
if ($request->user()->cannot('view',$school)) abort(403);
|
||||
if ($request->user()->cannot('view', $school)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return view('schools.show', ['school' => $school]);
|
||||
}
|
||||
|
||||
public function create(Request $request)
|
||||
{
|
||||
if ($request->user()->cannot('create', School::class)) abort(403);
|
||||
if ($request->user()->cannot('create', School::class)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return view('schools.create');
|
||||
}
|
||||
|
||||
public function edit(Request $request, School $school)
|
||||
{
|
||||
if ($request->user()->cannot('update',$school)) abort(403);
|
||||
if ($request->user()->cannot('update', $school)) {
|
||||
abort(403);
|
||||
}
|
||||
|
||||
return view('schools.edit', ['school' => $school]);
|
||||
}
|
||||
|
||||
public function update(Request $request, School $school)
|
||||
{
|
||||
if ($request->user()->cannot('update',$school)) abort(403);
|
||||
if ($request->user()->cannot('update', $school)) {
|
||||
abort(403);
|
||||
}
|
||||
request()->validate([
|
||||
'name' => ['required', 'min:3', 'max:30'],
|
||||
'address' => ['required'],
|
||||
|
|
@ -88,6 +96,7 @@ class SchoolController extends Controller
|
|||
'state' => request('state'),
|
||||
'zip' => request('zip'),
|
||||
]);
|
||||
|
||||
// TODO Handle redirect after updating school more elegantly
|
||||
return redirect('/schools/'.$school->id);
|
||||
}
|
||||
|
|
@ -97,6 +106,7 @@ class SchoolController extends Controller
|
|||
if (Auth::user()->school) {
|
||||
return redirect('/schools/'.Auth::user()->school->id);
|
||||
}
|
||||
|
||||
return redirect('/schools/create');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@
|
|||
<x-slot:title class="ml-3">Schools</x-slot:title>
|
||||
<x-slot:subtitle class="ml-3">Click school name to edit</x-slot:subtitle>
|
||||
<x-slot:title_block_right class="mr-3">
|
||||
<x-form.button href="/admin/schools/create">New School</x-form.button>
|
||||
<x-form.button href="{{ route('admin.schools.create') }}">New School</x-form.button>
|
||||
</x-slot:title_block_right>
|
||||
|
||||
<thead>
|
||||
|
|
|
|||
|
|
@ -96,8 +96,8 @@ Route::middleware(['auth', 'verified', CheckIfAdmin::class])->prefix('admin/')->
|
|||
Route::prefix('schools')->controller(\App\Http\Controllers\Admin\SchoolController::class)->group(function () {
|
||||
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}', 'show')->name('admin.schools.show');
|
||||
Route::get('/{school}/edit', 'edit')->name('admin.schools.edit');
|
||||
Route::patch('/{school}', 'update')->name('admin.schools.update');
|
||||
Route::post('/', 'store')->name('admin.schools.store');
|
||||
|
|
|
|||
Loading…
Reference in New Issue