S
S
SeokkySss2018-07-18 20:36:43
Laravel
SeokkySss, 2018-07-18 20:36:43

Laravel 5.6 - why is control not being transferred to the controller?

Immediately I enclose the code of the route, controller and view. Everything is as simple as possible, but, apparently, I do not understand something.
The task is to download the img file, which is in storage/app/public/uploads

Route::get('/download/{path}', '[email protected]')->name('download');

public function index()
{
     return view('upload')->with(['path' => 'uploads/foo.jpg']);
}

public function download($path)
{
     $file = storage_path($path);
     dd($file);
     return response()->download($file, 'filename.jpg')->deleteFileAfterSend(true);
 }

<a href="{{route('download', ['path' => $path])}}" style="padding: 10px; border: 1px solid darkblue;">Скачать</a>

Clicking on this link opens the page at 'download/uploads/foo.jpg', which says "Page not found". Tell me how should I do it right?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
JhaoDa, 2018-07-18
@JhaoDa

You need to add a slash to the pattern -  https://laravel.com/docs/5.6/routing#parameters-re...

V
Victor, 2018-07-18
@v_decadence

Route::get('view/{slashData?}', '[email protected]')
    ->where('slashData', '(.*)')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question