Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

ali2535's avatar

url in web.php not working

i write this code:

        $this->get('download' , function(){

           echo(111);
    });

but this not working and instead of download a zip file . why?

0 likes
20 replies
ali2535's avatar

hi guys . anyone know problem where is ? download url not working but any url workes. such as dl , downloads and .... why?

Paschal's avatar

If this is in your routes, do this instaed:

Route::get('download' , function(){
      echo(111);
});
Paschal's avatar

@ali2535 Ooh I understand now. Are you trying to force a file download?

If yes, Laravel download is bounded with responses, try this instead.

return response()->download($pathToFile);
ali2535's avatar

@paschal : yes my friend my problem is that following url not working. and istead of go to HomeController download a zip file .

Route::get('download' , 'HomeController@download');
Paschal's avatar

@ali2535 What is not working? Is the route not working at all? Or the download method of HomeController not being called?

ali2535's avatar

@paschal : no look at this:

Route::get('download' , function(){
    echo(111);
});

above code must print 111 but this download a zip file. very Amazing...

Paschal's avatar

@ali2535 Lmaooo that is very funny. Do you use artisan, run this command and reply with the output.

php artisan route:list
ali2535's avatar

@paschal . yes in route:list show download and app/download i copy all in other projects and works . in this project not working

Paschal's avatar

Post the output of route:list here let me see

ali2535's avatar

@paschal :

       |        | GET|HEAD  | app/download
             |                            | 
    App\Http\Controllers\HomeController@download                           | web        
      |
      |        | GET|HEAD  | bonecms_captcha
             | laravel-captcha            | 
      LaravelCaptcha\Controllers\CaptchaController@index                     | 
      web        |
       |        | GET|HEAD  | bonecms_captcha/html
             |                            | 
        LaravelCaptcha\Controllers\CaptchaController@html                      | 
       web        |
       |        | GET|HEAD  | contact-us
             | contact-us                 | 
         App\Http\Controllers\HomeController@ContactUS                          | 
      web        |
      |        | GET|HEAD  | download
Paschal's avatar

The output looks incomplete... Although I see app/download and download. Post the complete output

Snapey's avatar

you probably have a download file or folder in your website which is being picked up instead of your route.

Snapey's avatar

@pascal .htaccess first checks if there is a path to the requested object and if not then it rewrites the request to pass it to index.php.

This is how images, css and js are loaded direct without going through the framework

ali2535's avatar

@paschal : complete route is very much. it is big project and very route is in route:list. download and app/download are in route list.

ali2535's avatar

@Snapey : yes i have a apk file that when i type mysite.com/app/download it is correct and download file but when type mysite.com/download it download zip file (download and app/download refer to one function). (i havent zip file) . even i write in web.php

Route::get('download' , function(){
    dd(11);
});

above code also download zip file. i dont understand

Snapey's avatar

but do you have a download file or folder in the document root folder ?

The location of this will depend if you have something stupid like /public/ in your URLs

Paschal's avatar

I believe he definitely has a download folder in document root

ali2535's avatar

@snapey , @paschal

no i have a download folder in public . but before this why my route not working ?

Route::get('download' , function(){
        dd(11);
});

This route independent to download folder and must print 11 . but not working and download zip file.

Please or to participate in this conversation.