It presumes your url maps to the public/ directory. If you're using MAMP, give this a look: http://sawmac.com/mamp/virtual/ This will allow you to have something like http://client-site.dev which would route to your Sites/client-site/public directory.
The asset() helper prepends the base URL to the path you supply.
The base URL is the location of index.php (in this case: http://localhost/laravel/).
If you don't want index.php inside /public you will need to use public/ inside your asset path, like so: asset("public/css/style.css")
sgmurphy said:
The asset() helper prepends the base URL to the path you supply.
The base URL is the location of index.php (in this case: http://localhost/laravel/).
If you don't want index.php inside /public you will need to use public/ inside your asset path, like so: asset("public/css/style.css")
Hi sgmurphy, I have another problem. If I building a package which use asset() for get asset file url. Then I install this package to another project. How can I sync the asset folder in anytime I use this package?
I set up my XXAMP environment this way:
<VirtualHost *:85>
DocumentRoot "C:/xampp/htdocs/cats/public"
<Directory "C:/xampp/htdocs/cats/public">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory> </VirtualHost>Public is my base directory and public/index.php is the start file. public includes:
public/css
public/img
public/js
and
<link rel="stylesheet" href="{{asset('css/bootstrap.min.css')}}">works.
Change /Illuminate/Foundation/helpers.php/asset() function as follows:
function asset($path, $secure = null)
{
return app('url')->asset("public/".$path, $secure);
}
Learner said:
Change /Illuminate/Foundation/helpers.php/asset() function as follows:
function asset($path, $secure = null) { return app('url')->asset("public/".$path, $secure); }
Not working with L5
Learner said:
Change /Illuminate/Foundation/helpers.php/asset() function as follows:
function asset($path, $secure = null) { return app('url')->asset("public/".$path, $secure); }
Please do not do this. It is a really bad idea to modify framework code.
The change will not persist if you have to update the framework (bug fix). It will also not persist over deployments unless you commit the entire framework to your code repository (also a horrible idea). It also has the effect of possibly introducing bugs into your framework (again something you do not want to do).
The proper solution to this would be to create your own helper function. Take a look at this URL for some good practice suggestions on how to do that - http://stackoverflow.com/questions/28290332/best-practices-for-custom-helpers-on-laravel-5/28360186#28360186
I don't think that it is a good idea to update packages directly, instead of that we can move the files present in the public folder, by default, to root folder and update the index.php file like below.
require __DIR__.'/bootstrap/autoload.php';
$app = require_once __DIR__.'/bootstrap/app.php';
After this,
{{ asset('public/css/style.css') }}
will refer to the public/css/style.css in both local server and remote server.
The benefit of this method is, the composer update command might update vendor folder, but it won't affect us in any way.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community