Laravel资产网址 [英] Laravel assets url
问题描述
我已经安装了Laravel并开始尝试编写应用程序。我在与/ app相同的目录中为我的资产创建了一些目录。但是当我尝试访问我的localhost中的图像时,例如: http://localhost/assets/images/image.png
I have installed Laravel and began trying to write an app. I made some directories for my assets in the same directory as /app. But when I try to visit an image in my localhost for example: http://localhost/assets/images/image.png
我也尝试过: http://localhost/app/assets/images/image.png
当我试图在视图中设置背景图片时,我遇到了问题,并且它一直保持到404.
I ran into the problem when I was trying to set a background image in a view, and it kept going to 404.
这就是我的意思应用程序看起来像app /
This is what my app looks like under app/
->app
->assets
->commands
->config
->controllers
->database
->lang
->models
->start
->storage
->tests
->views
app.txt
routes.php
filters.php
但我收到有关请求的错误。我已经仔细检查过网址是否正确。
But I get errors about requests. I have double checked that the url is correct.
Symfony \ Component \ HttpKernel \ Exception \ NotFoundHttpException
推荐答案
您必须将所有资产放入 app / public
文件夹,要从您的视图中访问它们,您可以使用 asset()
帮助方法。
You have to put all your assets in app/public
folder, and to access them from your views you can use asset()
helper method.
Ex。您可以在视图中检索 assets / images / image.png
,如下所示:
Ex. you can retrieve assets/images/image.png
in your view as following:
< img src ={{asset('assets / images / image.png')}}>
这篇关于Laravel资产网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!