Search code examples
javascriptphplaravellaravel-5assets

Get the assets from another directory in laravel 5


We made a modulized app in laravel 5.0, So we want to get our css and js files from another directory (non public directory) such as a module directory. We searched the stacks and couldn't find any solution. How can we do that? Thanks

hint: the asset() function doesn't work except in public directory.


Solution

  • You have two options:

    1.You can setup a route to serve files from your directory.

    Route::get('assets/{filename}', function ($filename){
        $path =  'path_to_your_folder/'.$filename;
    
        $file = File::get($path);
        $type = File::mimeType($path);
    
        $response = Response::make($file, 200);
        $response->header("Content-Type", $type);
    
        return $response;
    });
    

    2.Make a symbolic link between the directories.

    ln -s /path/to/your_assets_folder /path/to/public/assets
    

    Got it from: this similar question