| Total Complexity | 7 |
| Total Lines | 94 |
| Duplicated Lines | 0 % |
| Coverage | 0% |
| Changes | 0 | ||
| 1 | <?php |
||
| 14 | class WorkSamplesController extends Controller |
||
| 15 | { |
||
| 16 | |||
| 17 | /** |
||
| 18 | * Show the form for editing the logged-in applicant's Work Samples |
||
| 19 | * |
||
| 20 | * @param Request $request |
||
|
1 ignored issue
–
show
|
|||
| 21 | * @return \Illuminate\Http\RedirectResponse |
||
| 22 | */ |
||
| 23 | public function editAuthenticated(Request $request): \Illuminate\Http\RedirectResponse |
||
| 27 | } |
||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * Show the form for editing the applicant's work samples |
||
| 32 | * |
||
| 33 | * @param Request $request Incoming request object. |
||
| 34 | * @param Applicant $applicant Incoming Applicant object. |
||
| 35 | * |
||
| 36 | * @return \Illuminate\View\View|\Illuminate\Contracts\View\Factory |
||
| 37 | */ |
||
| 38 | public function edit(Request $request, Applicant $applicant) |
||
| 39 | { |
||
| 40 | $applicant->load([ |
||
| 41 | 'work_samples', |
||
| 42 | 'skill_declarations.skill', |
||
| 43 | ]); |
||
| 44 | |||
| 45 | return view('applicant/profile_05_portfolio', [ |
||
| 46 | 'applicant' => $applicant, |
||
| 47 | 'profile' => Lang::get('applicant/profile_work_samples'), |
||
| 48 | ]); |
||
| 49 | } |
||
| 50 | |||
| 51 | /** |
||
| 52 | * Update the workSample in storage, or create new one. |
||
| 53 | * |
||
| 54 | * @param \Illuminate\Http\Request $request |
||
|
1 ignored issue
–
show
|
|||
| 55 | * @param \App\Models\WorkSample|null $workSample |
||
|
1 ignored issue
–
show
|
|||
| 56 | * @return \Illuminate\Http\Response |
||
| 57 | */ |
||
| 58 | public function update(Request $request, ?WorkSample $workSample = null) |
||
| 59 | { |
||
| 60 | $validator = new UpdateWorkSampleValidator(); |
||
| 61 | $validator->validate($request->input()); |
||
| 62 | |||
| 63 | if ($workSample === null) { |
||
| 64 | $workSample = new WorkSample(); |
||
| 65 | $workSample->applicant_id = $request->user()->applicant->id; |
||
| 66 | } |
||
| 67 | $workSample->fill([ |
||
| 68 | 'name' => $request->input('name'), |
||
| 69 | 'file_type_id' => $request->input('file_type_id'), |
||
| 70 | 'url' => $request->input('url'), |
||
| 71 | 'description' => $request->input('description'), |
||
| 72 | ]); |
||
| 73 | $workSample->save(); |
||
| 74 | |||
| 75 | //Attach relatives |
||
| 76 | $skillIds = $this->getRelativeIds($request->input(), 'skills'); |
||
| 77 | $workSample->skill_declarations()->sync($skillIds); |
||
| 78 | |||
| 79 | // if an ajax request, return the new object |
||
| 80 | if ($request->ajax()) { |
||
| 81 | $workSample->load('file_type'); |
||
| 82 | return $workSample->toJson(); |
||
|
1 ignored issue
–
show
|
|||
| 83 | } else { |
||
| 84 | return redirect()->back(); |
||
|
1 ignored issue
–
show
|
|||
| 85 | } |
||
| 86 | } |
||
| 87 | |||
| 88 | /** |
||
| 89 | * Delete the particular work sample from storage. |
||
| 90 | * |
||
| 91 | * @param \Illuminate\Http\Request $request |
||
|
1 ignored issue
–
show
|
|||
| 92 | * @param \App\Models\WorkSample $workSample |
||
|
1 ignored issue
–
show
|
|||
| 93 | * @return \Illuminate\Http\Response |
||
| 94 | */ |
||
| 95 | public function destroy(Request $request, WorkSample $workSample) |
||
| 108 | } |
||
| 109 | } |
||
| 110 |