Reputation: 860
when I try to get a path of any media using asset('images/image1.jpg')
it returns path as
instead of
here is a code that I am using to get image
<img src="{{ asset("images/image1.jpg") }}" />
Upvotes: 0
Views: 3033
Reputation: 2684
In laravel 5, the assets folder refer to the public folder, located in the root directory path.
In public folder, you can see index.php, this file executed very first, when someone open the application.
For removing the "public" folder path in URL, we should create a virtual host and assign the root directory path to public path.
I have xampp installed in my system.For creating a new Virtual Host, you need to open the vhosts file.
In my case it's located under the path. E:\xampp\apache\conf\extra\httpd-vhosts.conf
Copy the below code in your httpd-vhosts file
<VirtualHost 127.0.0.1>
ServerAdmin [email protected]
DocumentRoot "E:/xampp/htdocs/[yourprojectname]/public"
ServerName localhost.myproject
</VirtualHost>
You also need a entry in your windows hosts file. this file can be found under the below path.
C:\Windows\System32\drivers\etc\hosts
127.0.0.1 localhost.myproject
Restart your Xampp. Now your project can be accessed by "localhost.myproject" and you need not to add the public in your assets path.
Hope this all will help.
Upvotes: 1
Reputation: 4183
Generate a URL for an asset using the current scheme of the request (HTTP or HTTPS):
by default asset function doesn't return public as path
but you can add this path manually
<img src="{{ asset('public/images/image1.jpg) }}" />
Upvotes: 1