new FullCVCollection(CV::all()), ]); } public function show(CV $cv): InertiaResponse { return inertia('CV/Show', [ 'cv' => new FullCVResource($cv), 'cvInfo' => new CVInfoCollection($cv->info()->orderByDesc('id')->get()), ]); } public function create(): InertiaResponse { return inertia('CV/Create'); } public function store(CVRequest $request): RedirectResponse { CV::query() ->create([ 'token' => Str::random(50), 'recipient' => $request->get('recipient'), 'email' => $request->get('email'), 'phone_number' => $request->get('phone_number'), 'locations' => ($locations = $request->get('locations')) === [''] ? [] : $locations, 'mission' => ($mission = $request->get('mission')) === [''] ? [] : $mission, 'rodo' => ($rodo =$request->get('rodo')) === '' ? null : $rodo, 'position' => $request->get('position'), 'notes' => $request->get('notes'), ]); return redirect() ->route('admin.cv.store') ->with('success', 'Utworzono nowe CV dla firmy ' . $request->get('recipient')); } public function updateSendStatus(CV $cv): RedirectResponse { $cv->update([ 'sended' => true, 'sended_timestamp' => now() ]); return redirect() ->route('admin.cv.show', ['cv' => $cv]) ->with('success', 'Status wysłania ustawiono jako "wysłano".'); } public function edit(CV $cv): InertiaResponse { return inertia('CV/Edit', [ 'cv' => new FullCVResource($cv), ]); } public function update(CVRequest $request, CV $cv): RedirectResponse { $toUpdate = [ 'recipient' => $request->get('recipient'), 'email' => $request->get('email'), 'phone_number' => $request->get('phone_number'), 'locations' => ($locations = $request->get('locations')) === [''] ? [] : $locations, 'mission' => ($mission = $request->get('mission')) === [''] ? [] : $mission, 'rodo' => ($rodo =$request->get('rodo')) === '' ? null : $rodo, 'position' => $request->get('position'), 'notes' => $request->get('notes'), ]; if ($cv->sended && ! $request->boolean('sended')) { $toUpdate = array_merge($toUpdate, [ 'sended' => false, 'sended_timestamp' => null, ]); } else if (! $cv->sended && $request->boolean('sended')) { $toUpdate = array_merge($toUpdate, [ 'sended' => true, 'sended_timestamp' => now(), ]); } $cv->update($toUpdate); return redirect() ->back() ->with('success', 'Zaktualizowano CV dla firmy ' . $request->get('recipient')); } public function delete(CV $cv): InertiaResponse { return inertia('CV/ConfirmDelete', compact('cv')); } public function destroy(CV $cv): RedirectResponse { $name = $cv->recipient; $cv->delete(); return redirect() ->route('admin.cv.index') ->with('info', 'Usunięto CV dla firmy '. $name .'.'); } }