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