Used laravel validation for appeal form

Switched valdiation from checking for empty strings to using Laravel's
built in form validation. It's pretty.
This commit is contained in:
ro 2024-02-09 17:21:07 -06:00
parent 9e7c7c584e
commit fe67927c24

View file

@ -30,27 +30,23 @@ class AppealController extends Controller
'error' => 'Appeal already in process for Location',
]);
} else {
if (
empty($request->location)
|| empty($request->location_admin)
|| empty($request->sponsor)
|| empty($request->appeal_description)
) {
return back()->withErrors([
'error' => 'All fields are required',
]);
} else {
$new = Appeal::create([
'uuid' => Uuid::uuid4(),
'location' => $request->location,
'location_admin' => $request->location_admin,
'sponsor' => $request->sponsor,
'description' => $request->appeal_description,
'approved' => false,
'reviewed' => false,
]);
Mail::to(env('TBS_ADMIN_EMAIL'))->send(new LocationAppeal($request->location, $request->sponsor));
}
$clean = $request->validate([
'location' => ['required'],
'local_admin' => ['required'],
'local_sponsor' => ['required'],
'appeal_description' => ['required'],
]);
$new = Appeal::create([
'uuid' => Uuid::uuid4(),
'location' => $request->location,
'location_admin' => $request->location_admin,
'sponsor' => $request->sponsor,
'description' => $request->appeal_description,
'approved' => false,
'reviewed' => false,
]);
Mail::to(env('TBS_ADMIN_EMAIL'))->send(new LocationAppeal($request->location, $request->sponsor));
}
//return redirect('/appeals');
return back()->with('message', "Appeal Filed");