简体   繁体   English

laravel localhost / public / index.php不显示背景图像和svgs,但“ php artisan服务”显示它们

[英]laravel localhost/public/index.php doesn't show background image and svgs, but “php artisan serve” shows them

I have a small beautiful laravel project on my pc. 我的电脑上有一个漂亮的小laravel项目。

On the welcome.blade.php file, it has a background image. welcome.blade.php文件中,它具有背景图像。 And the image is located on 图像位于

public/images/ 公众/图片/

directory. 目录。

I have used this following CSS to call and represent them: 我使用以下CSS来调用和表示它们:

html, body {
color: #f4f6f7;
font-family: 'Nunito', sans-serif;
font-weight: 500;
height: 100vh;
margin: 0;

background-image: url('/images/back.png');
-webkit-background-size: cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size: cover;
}

This project contains a favicon icon too, and this is located as per laravel designed. 该项目也包含一个图标图标,并且按照laravel设计位于该图标中。

The problem is: 问题是:

When I go to localhost/got/public/index.php form my chrome 当我进入localhost/got/public/index.php表格时

it loads my project but can not show or load background image or favicon icon. 它会加载我的项目,但无法显示或加载背景图片或网站图标。

But when I run php artisan serve it runs well with no problem. 但是,当我运行php artisan serve它运行正常,没有问题。

What is the things i am missing? 我想念的是什么?

please use this : 请使用这个:

background-image: url('{{ asset('images/back.png') }}');
-webkit-background-size: cover;
-moz-background-size:cover;
-o-background-size:cover;
background-size: cover;
}

Try to add following code to your webpack.mix.js 尝试将以下代码添加到您的webpack.mix.js

.options({ processCssUrls: false, }) .options({processCssUrls:false,})

Your path differ when you use localhost/got/public/ . 使用localhost/got/public/时,路径不同。 Try make a virtual host for your project. 尝试为您的项目创建虚拟主机。

Well, here's the WHY part. 好吧,这是为什么。 When you use artisan serve, the image path (that is RELATIVE: /images/back.png) refers to http://localhost:8000/images/back.png . 使用手工艺品时,图片路径(即RELATIVE:/images/back.png)是指http://localhost:8000/images/back.png And when you use your local server the images refers to http://localhost/images/back.png again BUT your address is localhost/got/public/images/back.png . 当您使用本地服务器时,图像再次引用http://localhost/images/back.png但您的地址是localhost/got/public/images/back.png

加载头文件(包括.css文件)时,请使用{{ asset("filesurl") }}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM