Passed
Push — dev ( 103b07...7e3580 )
by Yonathan
03:59 queued 12s
created

JobController   A

Complexity

Total Complexity 40

Size/Duplication

Total Lines 461
Duplicated Lines 0 %

Test Coverage

Coverage 80.86%

Importance

Changes 7
Bugs 0 Features 0
Metric Value
wmc 40
eloc 233
c 7
b 0
f 0
dl 0
loc 461
ccs 169
cts 209
cp 0.8086
rs 9.2

9 Methods

Rating   Name   Duplication   Size   Complexity  
A downloadApplicants() 0 51 5
A hrIndex() 0 6 1
A index() 0 29 2
A managerIndex() 0 29 3
A destroy() 0 3 1
A createAsManager() 0 17 1
A fillAndSaveJobPosterQuestions() 0 28 5
D show() 0 154 17
A store() 0 31 4

How to fix   Complexity   

Complex Class

Complex classes like JobController often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes.

Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.

While breaking up the class, it is a good idea to analyze how other classes use JobController, and based on these observations, apply Extract Interface, too.

1
<?php
2
3
namespace App\Http\Controllers;
4
5
use Illuminate\Support\Facades\Lang;
6
use Illuminate\Support\Facades\Auth;
7
use Illuminate\Http\Request;
8
use App\Http\Controllers\Controller;
9
use App\Models\JobApplication;
10
use Carbon\Carbon;
11
use App\Models\JobPoster;
12
use App\Models\JobPosterQuestion;
13
use App\Models\Lookup\ApplicationStatus;
14
use App\Models\Lookup\CitizenshipDeclaration;
15
use App\Models\Lookup\JobPosterStatus;
16
use App\Models\Lookup\VeteranStatus;
17
use App\Models\Manager;
18
use App\Services\JobPosterDefaultQuestions;
19
use Mcamara\LaravelLocalization\Facades\LaravelLocalization;
20
use App\Services\Validation\JobPosterValidator;
21
use Facades\App\Services\WhichPortal;
22
use Illuminate\Support\Facades\Response;
23
use Illuminate\Support\Facades\Validator;
24
25
class JobController extends Controller
26
{
27
    /**
28
     * Display a listing of JobPosters.
29
     *
30
     * @return \Illuminate\Http\Response
31
     */
32
    public function index()
33
    {
34
        // If true, show the Paused due to COVID-19 message.
35
        $emergency_response = config('seasonal.is_covid_emergency');
0 ignored issues
show
Bug introduced by
The function config was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

35
        $emergency_response = /** @scrutinizer ignore-call */ config('seasonal.is_covid_emergency');
Loading history...
36
37
        // Find published jobs that are currently open for applications.
38
        // Eager load required relationships: Department, Province, JobTerm.
39
        // Eager load the count of submitted applications, to prevent the relationship
40
        // from being actually loaded and firing off events.
41
        $jobs = JobPoster::where('internal_only', false)
42
            ->where('department_id', '!=', config('app.strategic_response_department_id'))
43
            ->where('job_poster_status_id', JobPosterStatus::where('key', 'live')->first()->id)
44
            ->with([
45
                'department',
46
                'province',
47
                'job_term',
48
            ])
49
            ->withCount([
50
                'submitted_applications',
51
            ])
52
            ->get();
53
54
        $null_alert = $emergency_response
55
            ? Lang::get('applicant/job_index.index.covid_null_alert')
56
            : Lang::get('applicant/job_index.index.null_alert');
57
        return view('applicant/job_index', [
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

57
        return /** @scrutinizer ignore-call */ view('applicant/job_index', [
Loading history...
58
            'job_index' => Lang::get('applicant/job_index'),
59
            'null_alert' => $null_alert,
60
            'jobs' => $jobs
61
        ]);
62
    }
63
64
    /**
65
     * Display a listing of a manager's JobPosters.
66
     *
67
     * @return \Illuminate\Http\Response
68
     */
69
    public function managerIndex()
70
    {
71
        $manager = Auth::user()->manager;
72
73 1
        $jobs = JobPoster::where('manager_id', $manager->id)
74
            ->with('classification')
75 1
            ->withCount('submitted_applications')
76 1
            ->get();
77 1
78 1
        foreach ($jobs as &$job) {
79
            $chosen_lang = $job->chosen_lang;
80 1
81
            // Show chosen lang title if current title is empty.
82 1
            if (empty($job->title)) {
83
                $job->title = $job->getTranslation('title', $chosen_lang);
84 1
                $job->trans_required = true;
85
            }
86
87
            // Always preview and edit in the chosen language.
88
            $job->preview_link = LaravelLocalization::getLocalizedURL($chosen_lang, route('manager.jobs.show', $job));
0 ignored issues
show
Bug introduced by
The function route was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

88
            $job->preview_link = LaravelLocalization::getLocalizedURL($chosen_lang, /** @scrutinizer ignore-call */ route('manager.jobs.show', $job));
Loading history...
89
            $job->edit_link = LaravelLocalization::getLocalizedURL($chosen_lang, route('manager.jobs.edit', $job));
90
        }
91
92
93
        return view('manager/job_index', [
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

93
        return /** @scrutinizer ignore-call */ view('manager/job_index', [
Loading history...
94
            // Localization Strings.
95 1
            'jobs_l10n' => Lang::get('manager/job_index'),
96
            // Data.
97
            'jobs' => $jobs,
98 1
        ]);
99 1
    }
100
101
    /**
102 1
     * Display a listing of a hr advisor's JobPosters.
103
     *
104
     * @return \Illuminate\Http\Response
105 1
     */
106 1
    public function hrIndex(Request $request)
107 1
    {
108
        $hrAdvisor = $request->user()->hr_advisor;
109
        return view('hr_advisor/job_index', [
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

109
        return /** @scrutinizer ignore-call */ view('hr_advisor/job_index', [
Loading history...
110
            'title' => Lang::get('hr_advisor/job_index.title'),
111
            'hr_advisor_id' => $hrAdvisor->id
112 1
        ]);
113
    }
114 1
115 1
116
117
118
    /**
119
     * Delete a draft Job Poster.
120
     *
121
     * @param  \Illuminate\Http\Request $request   Incoming request object.
122
     * @param  \App\Models\JobPoster    $jobPoster Job Poster object.
123
     * @return \Illuminate\Http\Response
124
     */
125
    public function destroy(Request $request, JobPoster $jobPoster)
126
    {
127
        $jobPoster->delete();
128
    }
129
130
    /**
131
     * Display the specified job poster.
132
     *
133
     * @param  \Illuminate\Http\Request $request   Incoming request object.
134
     * @param  \App\Models\JobPoster    $jobPoster Job Poster object.
135
     * @return \Illuminate\Http\Response
136
     */
137
    public function show(Request $request, JobPoster $jobPoster)
138 6
    {
139
        $jobPoster->load([
140 6
            'department',
141 6
            'criteria.skill.skill_type',
142
            'manager.team_culture',
143
            'manager.work_environment'
144
        ]);
145
146
        $user = Auth::user();
147 6
148
        // TODO: Improve workplace photos, and reference them in template direction from WorkEnvironment model.
149
        $workplacePhotos = [];
150 6
        foreach ($jobPoster->manager->work_environment->workplace_photo_captions as $photoCaption) {
151 6
            $workplacePhotos[] = [
152
                'description' => $photoCaption->description,
153
                'url' => '/images/user.png'
154
            ];
155
        }
156
157
        // TODO: replace route('manager.show',manager.id) in templates with link using slug.
158
        $essential_hard = $jobPoster->criteria->filter(
159
            function ($value, $key) {
160 6
                return $value->criteria_type->name == 'essential' &&
161
                    $value->skill->skill_type->name == 'hard';
162 4
            }
163 6
        )->sortBy('skill.name');
164
        $essential_soft = $jobPoster->criteria->filter(
165 6
            function ($value, $key) {
166
                return $value->criteria_type->name == 'essential' &&
167 4
                    $value->skill->skill_type->name == 'soft';
168 6
            }
169
        )->sortBy('skill.name');
170
        $asset_hard = $jobPoster->criteria->filter(
171
            function ($value, $key) {
172 6
                return $value->criteria_type->name == 'asset' &&
173
                    $value->skill->skill_type->name == 'hard';
174 6
            }
175 6
        )->sortBy('skill.name');
176
        $asset_soft = $jobPoster->criteria->filter(
177 4
            function ($value, $key) {
178 4
                return $value->criteria_type->name == 'asset' &&
179 4
                    $value->skill->skill_type->name == 'soft';
180
            }
181 2
        )->sortBy('skill.name');
182
        $criteria = [
183 1
            'essential' => $essential_hard->merge($essential_soft),
184 1
            'asset' => $asset_hard->merge($asset_soft),
185 1
        ];
186
187 1
        $jobLang = Lang::get('applicant/job_post');
188
189 1
        $applyButton = [];
190 1
        if (WhichPortal::isManagerPortal()) {
191 1
            $applyButton = [
192
                'href' => route('manager.jobs.edit', $jobPoster->id),
0 ignored issues
show
Bug introduced by
The function route was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

192
                'href' => /** @scrutinizer ignore-call */ route('manager.jobs.edit', $jobPoster->id),
Loading history...
193
                'title' => $jobLang['apply']['edit_link_title'],
194
                'text' => $jobLang['apply']['edit_link_label'],
195
            ];
196
        } elseif (WhichPortal::isHrPortal()) {
197
            if ($jobPoster->hr_advisors->contains('user_id', $user->id)) {
198
                $applyButton = [
199
                    'href' => route('hr_advisor.jobs.summary', $jobPoster->id),
200
                    'title' => null,
201 6
                    'text' => Lang::get('hr_advisor/job_summary.summary_title'),
202 6
                ];
203
            } else {
204 6
                $applyButton = [
205 6
                    'href' => route('hr_advisor.jobs.index'),
206 6
                    'title' => null,
207 6
                    'text' => Lang::get('hr_advisor/job_index.title'),
208 6
                ];
209 6
            }
210 6
        } elseif (Auth::check() && $jobPoster->isOpen()) {
211 6
            $application = JobApplication::where('applicant_id', Auth::user()->applicant->id)
212 6
                ->where('job_poster_id', $jobPoster->id)->first();
213 6
            // If applicants job application is not draft anymore then link to application preview page.
214
            if ($application != null && $application->application_status->name != 'draft') {
215
                $applyButton = [
216
                    'href' => route('applications.show', $application->id),
217
                    'title' => $jobLang['apply']['view_link_title'],
218
                    'text' => $jobLang['apply']['view_link_label'],
219
                ];
220
            } else {
221
                $applyButton = [
222
                    'href' => route('job.application.edit.1', $jobPoster->id),
223
                    'title' => $jobLang['apply']['apply_link_title'],
224 2
                    'text' => $jobLang['apply']['apply_link_label'],
225
                ];
226 2
            }
227 2
        } elseif (Auth::guest() && $jobPoster->isOpen()) {
228
            $applyButton = [
229 2
                'href' => route('job.application.edit.1', $jobPoster->id),
230
                'title' => $jobLang['apply']['login_link_title'],
231 2
                'text' => $jobLang['apply']['login_link_label'],
232 2
            ];
233 2
        } else {
234
            $applyButton = [
235
                'href' => null,
236 2
                'title' => null,
237
                'text' => $jobLang['apply']['job_closed_label'],
238
            ];
239
        }
240
241
        $jpb_release_date = strtotime('2019-08-21 16:18:17');
242
        $job_created_at = strtotime($jobPoster->created_at);
243
244
        // If the poster is part of the Strategic Talent Response dept, use the talent stream template.
245
        // Else, If the job poster is created after the release of the JPB.
246
        // Then, render with updated poster template.
247
        // Else, render with old poster template.
248
        if ($jobPoster->isInStrategicResponseDepartment()) {
249
            return view(
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

249
            return /** @scrutinizer ignore-call */ view(
Loading history...
250
                'applicant/strategic_response_job_post',
251
                [
252
                    'job_post' => $jobLang,
253
                    'frequencies' => Lang::get('common/lookup/frequency'),
254
                    'skill_template' => Lang::get('common/skills'),
255
                    'job' => $jobPoster,
256
                    'manager' => $jobPoster->manager,
257 1
                    'criteria' => $criteria,
258
                    'apply_button' => $applyButton,
259 1
                ]
260
            );
261
        } elseif ($job_created_at > $jpb_release_date) {
262
            // Updated job poster (JPB).
263
            return view(
264
                'applicant/jpb_job_post',
265
                [
266
                    'job_post' => $jobLang,
267
                    'frequencies' => Lang::get('common/lookup/frequency'),
268
                    'skill_template' => Lang::get('common/skills'),
269 1
                    'job' => $jobPoster,
270
                    'manager' => $jobPoster->manager,
271 1
                    'criteria' => $criteria,
272
                    'apply_button' => $applyButton,
273
                ]
274 1
            );
275
        } else {
276
            // Old job poster.
277 1
            return view(
278 1
                'applicant/job_post',
279 1
                [
280 1
                    'job_post' => $jobLang,
281
                    'frequencies' => Lang::get('common/lookup/frequency'),
282
                    'manager' => $jobPoster->manager,
283
                    'manager_profile_photo_url' => '/images/user.png', // TODO get real photo.
284
                    'team_culture' => $jobPoster->manager->team_culture,
285
                    'work_environment' => $jobPoster->manager->work_environment,
286
                    'workplace_photos' => $workplacePhotos,
287
                    'job' => $jobPoster,
288
                    'criteria' => $criteria,
289
                    'apply_button' => $applyButton,
290
                    'skill_template' => Lang::get('common/skills'),
291 1
                ]
292
            );
293 1
        }
294 1
    }
295
296 1
    /**
297 1
     * Display the form for editing an existing Job Poster
298 1
     * Only allows editing fields that don't appear on the react-built Job Poster Builder.
299 1
     *
300
     * @param  \Illuminate\Http\Request $request   Incoming request object.
301
     * @param  \App\Models\JobPoster    $jobPoster Job Poster object.
302 1
     * @return \Illuminate\Http\Response
303
     */
304 1
    public function edit(Request $request, JobPoster $jobPoster)
305
    {
306 1
        $manager = $jobPoster->manager;
307
308 1
        $defaultQuestionManager = new JobPosterDefaultQuestions();
309 1
        $defaultQuestionManager->initializeQuestionsIfEmpty($jobPoster);
310
311 1
        return view(
0 ignored issues
show
Bug introduced by
The function view was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

311
        return /** @scrutinizer ignore-call */ view(
Loading history...
312 1
            'manager/job_create',
313 1
            [
314 1
                // Localization Strings.
315
                'job_l10n' => Lang::get('manager/job_edit'),
316
                // Data.
317 1
                'manager' => $manager,
318
                'job' => $jobPoster,
319 1
                'form_action_url' => route('admin.jobs.update', $jobPoster),
0 ignored issues
show
Bug introduced by
The function route was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

319
                'form_action_url' => /** @scrutinizer ignore-call */ route('admin.jobs.update', $jobPoster),
Loading history...
320
            ]
321 1
        );
322
    }
323 1
324 1
    /**
325
     * Create a blank job poster for the specified manager
326
     *
327
     * @param  \App\Models\Manager $manager Incoming Manager object.
328 1
     * @return \Illuminate\Http\Response Job Create view
329 1
     */
330
    public function createAsManager(Manager $manager)
331
    {
332 1
        $jobPoster = new JobPoster();
333 1
        $jobPoster->manager_id = $manager->id;
334
335
        // Save manager-specific info to the job poster - equivalent to the intro step of the JPB
336
        $divisionEn = $manager->getTranslation('division', 'en');
337 1
        $divisionFr = $manager->getTranslation('division', 'fr');
338
        $jobPoster->fill([
339 1
            'department_id' => $manager->user->department_id,
340
            'division' => ['en' => $divisionEn],
341 1
            'division' => ['fr' => $divisionFr],
342
        ]);
343 1
344 1
        $jobPoster->save();
345 1
346
        return redirect()->route('manager.jobs.edit', $jobPoster->id);
0 ignored issues
show
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

346
        return /** @scrutinizer ignore-call */ redirect()->route('manager.jobs.edit', $jobPoster->id);
Loading history...
347 1
    }
348
349 1
    /**
350 1
     * Update a resource in storage
351 1
     * NOTE: Only saves fields that are not on the react-built Job Poster Builder
352
     *
353 1
     * @param  \Illuminate\Http\Request $request   Incoming request object.
354 1
     * @param  \App\Models\JobPoster    $jobPoster Optional Job Poster object.
355
     * @return \Illuminate\Http\Response
356
     */
357 1
    public function store(Request $request, JobPoster $jobPoster)
358
    {
359 1
        // Don't allow edits for published Job Posters
360 1
        // Also check auth while we're at it.
361 1
        $this->authorize('update', $jobPoster);
362 1
        JobPosterValidator::validateUnpublished($jobPoster);
363 1
364 1
        $input = $request->input();
365 1
366 1
        if ($jobPoster->manager_id == null) {
367 1
            $jobPoster->manager_id = $request->user()->manager->id;
368 1
            $jobPoster->save();
369 1
        }
370
371
        if ($request->input('question')) {
372
            $validator = Validator::make($request->input('question'), [
373
                '*.question.*' => 'required|string',
374
            ], [
375
                'required' => Lang::get('validation.custom.job_poster_question.required'),
376
                'string' => Lang::get('validation.custom.job_poster_question.string')
377
            ]);
378
379
            if ($validator->fails()) {
380
                $request->session()->flash('errors', $validator->errors());
381 6
                return redirect(route('admin.jobs.edit', $jobPoster->id));
0 ignored issues
show
Bug introduced by
The function redirect was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

381
                return /** @scrutinizer ignore-call */ redirect(route('admin.jobs.edit', $jobPoster->id));
Loading history...
Bug introduced by
The function route was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

381
                return redirect(/** @scrutinizer ignore-call */ route('admin.jobs.edit', $jobPoster->id));
Loading history...
382
            }
383
        }
384
385 6
        $this->fillAndSaveJobPosterQuestions($input, $jobPoster, true);
386 6
387 6
        return redirect(route('manager.jobs.show', $jobPoster->id));
388
    }
389
390
    /**
391
     * Fill Job Poster's questions and save
392 6
     *
393
     * @param  mixed[]               $input     Field values.
394 6
     * @param  \App\Models\JobPoster $jobPoster Job Poster object.
395
     * @param  boolean               $replace   Remove existing relationships.
396 6
     * @return void
397
     */
398
    protected function fillAndSaveJobPosterQuestions(array $input, JobPoster $jobPoster, bool $replace): void
399
    {
400
        if ($replace) {
401 6
            $jobPoster->job_poster_questions()->delete();
402
        }
403 6
404
        if (!array_key_exists('question', $input) || !is_array($input['question'])) {
405 6
            return;
406
        }
407 6
408
        foreach ($input['question'] as $question) {
409 6
            $jobQuestion = new JobPosterQuestion();
410
            $jobQuestion->job_poster_id = $jobPoster->id;
411
            $jobQuestion->fill(
412
                [
413
                    'question' => [
414
                        'en' => $question['question']['en'],
415
                        'fr' => $question['question']['fr']
416
417
                    ],
418
                    'description' => [
419 6
                        'en' => $question['description']['en'],
420
                        'fr' => $question['description']['fr']
421 6
                    ]
422
                ]
423 6
            );
424 6
            $jobPoster->save();
425 6
            $jobQuestion->save();
426 6
        }
427 6
    }
428 6
429 6
    /**
430 6
     * Downloads a CSV file with the applicants who have applied to the job poster.
431 6
     *
432 6
     * @param  \App\Models\JobPoster $jobPoster Job Poster object.
433 6
     * @return \Symfony\Component\HttpFoundation\BinaryFileResponse
434 6
     */
435 6
    protected function downloadApplicants(JobPoster $jobPoster)
436 6
    {
437
        $tables = [];
438 6
        // The first row in the array represents the names of the columns in the spreadsheet.
439 6
        $tables[0] = ['Status', 'Applicant Name', 'Email', 'Language'];
440 6
441 6
        $application_status_id = ApplicationStatus::where('name', 'submitted')->first()->id;
442 6
        $applications = JobApplication::where('job_poster_id', $jobPoster->id)
443 6
            ->where('application_status_id', $application_status_id)
444
            ->get();
445
446 6
        $index = 1;
447 6
        foreach ($applications as $application) {
448 6
            $status = '';
449 6
            $username = $application->user_name;
450 6
            $user_email = $application->user_email;
451 6
            $language = strtoupper($application->preferred_language->name);
452
            // If the applicants veteran status name is NOT 'none' then set status to veteran.
453
            $non_veteran = VeteranStatus::where('name', 'none')->first()->id;
454
            if ($application->veteran_status_id != $non_veteran) {
455 6
                $status = 'Veteran';
456 6
            } else {
457
                // Check if the applicant is a canadian citizen.
458
                $canadian_citizen = CitizenshipDeclaration::where('name', 'citizen')->first()->id;
459
                if ($application->citizenship_declaration->id == $canadian_citizen) {
460
                    $status = 'Citizen';
461
                } else {
462
                    $status = 'Non-citizen';
463
                }
464
            }
465
            $tables[$index] = [$status, $username, $user_email, $language];
466 6
            $index++;
467
        }
468 6
469 6
        $filename = $jobPoster->id . '-' . 'applicants-data.csv';
470
471
        // Open file.
472 6
        $file = fopen($filename, 'w');
473 6
        // Iterate through tables and add each line to csv file.
474
        foreach ($tables as $line) {
475
            fputcsv($file, $line);
0 ignored issues
show
Bug introduced by
It seems like $file can also be of type false; however, parameter $handle of fputcsv() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

475
            fputcsv(/** @scrutinizer ignore-type */ $file, $line);
Loading history...
476
        }
477
        // Close open file.
478
        fclose($file);
0 ignored issues
show
Bug introduced by
It seems like $file can also be of type false; however, parameter $handle of fclose() does only seem to accept resource, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

478
        fclose(/** @scrutinizer ignore-type */ $file);
Loading history...
479
480
        $headers = [
481
            'Content-Type' => 'text/csv',
482
            'Content-Disposition' => 'attachment; filename=' . $filename,
483
        ];
484
485
        return Response::download($filename, $filename, $headers);
486
    }
487
}
488