thebadspace/app/Http/Controllers/AppealController.php

60 lines
2 KiB
PHP
Raw Normal View History

<?php
namespace App\Http\Controllers;
use App\Mail\LocationAppeal;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Mail;
use Ramsey\Uuid\Uuid;
use App\Models\Appeal;
class AppealController extends Controller
{
/**
* Send appeal request
*/
public function sendAppeal(Request $request)
{
//$order = Order::findOrFail($request->order_id);
$token = csrf_token();
if ($request->h1 != '' || $request->question != 2) {
return back()->withErrors([
'error' => 'Invalid Request',
]);
} else {
$check = Appeal::where("location", $request->location)->first();
if ($check) {
return back()->withErrors([
'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));
}
}
//return redirect('/appeals');
return back()->with('message', "Appeal Filed");
};
}
}