. */ namespace App\Http\Controllers; use App\Application; use App\Exceptions\IncompleteApplicationException; use App\Exceptions\UnavailableApplicationException; use App\Exceptions\VacancyNotFoundException; use App\Services\ApplicationService; use Illuminate\Http\Request; use Illuminate\Support\Facades\Auth; class ApplicationController extends Controller { private $applicationService; public function __construct(ApplicationService $applicationService) { $this->applicationService = $applicationService; } public function showUserApps() { return view('dashboard.user.applications') ->with('applications', Auth::user()->applications); } public function showUserApp(Request $request, Application $application) { $this->authorize('view', $application); if (!is_null($application)) { return view('dashboard.user.viewapp') ->with( [ 'application' => $application, 'comments' => $application->comments, 'structuredResponses' => json_decode($application->response->responseData, true), 'formStructure' => $application->response->form, 'vacancy' => $application->response->vacancy, 'canVote' => $this->applicationService->canVote($application->votes), ] ); } else { $request->session()->flash('error', __('The application you requested could not be found.')); } return redirect()->back(); } public function showAllApps(Request $request) { $this->authorize('viewAny', Application::class); return view('dashboard.appmanagement.all'); } public function renderApplicationForm($vacancySlug) { return $this->applicationService->renderForm($vacancySlug); } public function saveApplicationAnswers(Request $request, $vacancySlug) { try { $this->applicationService->fillForm(Auth::user(), $request->all(), $vacancySlug); } catch (VacancyNotFoundException | IncompleteApplicationException | UnavailableApplicationException $e) { return redirect() ->back() ->with('error', $e->getMessage()); } return redirect() ->back() ->with('success', __('Thank you! Your application has been processed and our team will get to it shortly.')); } public function updateApplicationStatus(Request $request, Application $application, $newStatus) { $messageIsError = false; $this->authorize('update', Application::class); try { $status = $this->applicationService->updateStatus($application, $newStatus); } catch (\LogicException $ex) { return redirect() ->back() ->with('error', $ex->getMessage()); } return redirect() ->back() ->with('success', $status); } /** * @throws \Illuminate\Auth\Access\AuthorizationException * @throws \Exception */ public function delete(Request $request, Application $application) { $this->authorize('delete', $application); $this->applicationService->delete($application); return redirect() ->back() ->with('success', __('Application deleted. Comments, appointments and responses have also been deleted.')); } }