Diego Cespedes
Diego Cespedes

Reputation: 1353

Laravel - GET request download logout automaticlly

i have a download file link like this:

<a href="{{ route('download_document', ['file' => 'agos.pdf']) }}" class=" text-info" style="cursor: pointer;">Download file</a>

ROUTES

Route::group(['middleware' => ['web','auth','Admin','active'], 'prefix' => 'admin'], function(){

    // USERS
    Route::resource('user','UserController');
    Route::post('user/permissions/update','UserController@update_permission')->name('update_user_permissions');

    // MODULI
    Route::resource('module','ModuleController');

    // MODULISITICA
    Route::resource('modulistica','ModulisticaController');

Route::post('modulistica_cliente','ModulisticaController@update_client_module')->name('modulistica_post_cliente');
    Route::post('modulistica_prodotto','ModulisticaController@update_product_module')->name('modulistica_post_prodotto');
    Route::get('modulistica/download/cliente/{file}','ModulisticaController@download_cliente')->name('modulistica_download_cliente');
    Route::get('modulistica/download/{file}','ModulisticaController@download_module')->name('modulistica_download_module');
    Route::get('modulistica/download/prodotto/{file}','ModulisticaController@download_prodotto')->name('modulistica_download_prodotto');

    // UTILITY
    Route::post('utility/become/client','UtilityController@become_client')->name('utility_become_client');
    Route::resource('loan','LoanController');
    Route::get('area_download/document/{file}', function ($file){

        $path_file = storage_path().'/app/public/documents/'.$file;
        return response()->download($path_file, $file);

    })->name('download_document');

});

ERROR

Arrival at the "https://mysite.it/admin/loan" view without problems. When I click on the GET link it redirects me to the LOGIN, but being my user logged in by login redirects me to "https://mysite.it/home".

I did some tests getting the following information:

So my conclusions are that the problem is in the middleware "Web" or "Auth" but I can not understand why. Place the entire group of routes, if it can be useful. If you need more on the routes, I can attach screenshots!

I would appreciate your help thank you!

Upvotes: 0

Views: 131

Answers (2)

Diego Cespedes
Diego Cespedes

Reputation: 1353

I found the solution! the problem was that my get request was made this way.

https://mysite.it/admin/area_download/document/example.pdf

the final PDF extension creates system error. Avoiding the final extension such as:

https://mysite.it/admin/area_download/document/example.pdf/go

Problem solved!

Upvotes: 1

kmjadeja
kmjadeja

Reputation: 114

If you just allow downloading a file without any authentication then, You can try this :

Blade File

<a href="{{ Storage::url($file_name) }}" download class=" text-info" style="cursor: pointer;">Download file</a>

From this user can directly download the file. Just need to add file path in href and download attribute.

or else remove the middleware AUTH if you don't want to Authenticate the user.


And you want to authenticate the user then need route:list and middleware details.

Upvotes: 1

Related Questions