Laravel 资产网址 [英] Laravel assets url

查看:20
本文介绍了Laravel 资产网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经安装了 Laravel 并开始尝试编写一个应用程序.我在与/app 相同的目录中为我的资产创建了一些目录.但是当我尝试访问本地主机中的图像时,例如: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.

例如.您可以在您的视图中检索 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆