Asked  1 Year ago    Answers:  5   Viewed   36 times

in laravel application i'm trying to achieve a button inside view that can allow user to download file without navigating to any other view or route now i have two issues: (1) below function throwing

the file "/public/download/info.pdf" does not exist

(2) download button should not navigate user to anywhere and rather just download files on a same view, my current settings, routing a view to '/download'

here is how im trying to achieve:


  <a href="/download" class="btn btn-large pull-right"><i class="icon-download-alt"> </i> download brochure </a>

route :

route::get('/download', 'homecontroller@getdownload');

controller :

public function getdownload(){
        //pdf file is stored under project/public/download/info.pdf
        return response::download($file);



try this.

public function getdownload()
    //pdf file is stored under project/public/download/info.pdf
    $file= public_path(). "/download/info.pdf";

    $headers = array(
              'content-type: application/pdf',

    return response::download($file, 'filename.pdf', $headers);

"./download/info.pdf"will not work as you have to give full physical path.

update 20/05/2016

laravel 5, 5.1, 5.2 or 5.* users can use the following method instead of response facade. however, my previous answer will work for both laravel 4 or 5. (the $header array structure change to associative array =>- the colon after 'content-type' was deleted - if we don't do those changes then headers will be added in wrong way: the name of header wil be number started from 0,1,...)

$headers = [
              'content-type' => 'application/pdf',

return response()->download($file, 'filename.pdf', $headers);
Wednesday, June 2, 2021

i don't know whether laravel supports the change of auth table name on fly or not. i can suggest you a quick solution.

according to generalization theory of database design, you should store same type of information to one entity set. and according to specialization theory, if entity set can have various types of information for each entity, break them down into sub entity sets.


  • create user_types table with column id & name (store user type names here)
  • create table users with 4 columns id, email/username, password & user_type_id (user_type_id is foreign key references id of user_types)
  • create 3 separate tables named administrators, parents or employees. all 3 tables should have one column user_id which is a foreign key references users table.
  • create relationship in model
  • after a user login, you can determine which type of user he/she is from the user<->user_type relation
  • you can get rid of the usertype dropdown from login page view now (you were disclosing some important information (3 user types) about your application to the whole planet, isn't it harmful for your application?)

more info about generalization & specialization: generalization, specialization and aggregation

Saturday, May 29, 2021

i know this is an old question. i'm just posting this answer for historical purposes:

laravel now has the possibility to localize the resources.

localizing resource uris by default, route::resource will create resource uris using english verbs. if you need to localize the create and edit action verbs, you may use the route::resourceverbs method. this may be done in the boot method of your appserviceprovider:

use illuminatesupportfacadesroute;

 * bootstrap any application services.
 * @return void

public function boot() {
        'create' => 'crear',
        'edit' => 'editar',
    ]); } 

once the verbs have been customized, a resource route registration such as route::resource('fotos', 'photocontroller') will produce the following uris:


Saturday, May 29, 2021

to see the downloaded files, you must have file manager app installed in your phone. steps to view downloaded files:

  1. open file manager app.
  2. go to storage -> sdcard
  3. go to android -> data -> "your package name" eg.
  4. here are all your downloads.

path is: storage/sdcard/android/data/"your package"

use below methos to save files in download folder

.setdestinationinexternalfilesdir(this, dir, "abc.png");
Thursday, October 14, 2021

you need the list of files on the ftp server. which isn't straightforward as each ftp server might return a different format of file listing...

anyway, the ftpgetresp.c example shows a way to do it, i think. ftp custom customrequest suggests another way.

Thursday, January 13, 2022
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :