Laravel 5 找不到 css 文件 [英] Laravel 5 not finding css files

查看:32
本文介绍了Laravel 5 找不到 css 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚在 MAMP 上安装了一个 Laravel 5 项目,但我的页面没有找到 css 文件.

I've just installed a Laravel 5 project on MAMP and my pages are not finding the css files.

这是我的 app.blade.php 文件中 css 的链接:

This is the link to my css in my app.blade.php file:

<link href="/css/app.css" rel="stylesheet">

我的 .htaccess 文件有这一行:

And my .htaccess file has this line:

RewriteBase /laravel-site/laravel-5-app/public/

在 config 文件夹中,我的 app.php 文件包含以下内容:

In the config folder my app.php file contains this:

'url' => 'http://localhost:8888/laravel-site/laravel-5-app/public/',

但是当我打开这个页面时:http://localhost:8888/laravel-site/laravel-5-app/public/auth/login 并检查开发人员工具,它正在此位置查找 css 文件:http://localhost:8888/css/app.css

But when I open up this page: http://localhost:8888/laravel-site/laravel-5-app/public/auth/login and check the developer tools, it is looking for the css file at this location: http://localhost:8888/css/app.css

作为旁注,如果我访问这个 url:http://localhost:8888/laravel-site/laravel-5-app/public/ 我得到了正确的欢迎页面.

Just as a side note, if I go to this url: http://localhost:8888/laravel-site/laravel-5-app/public/ I get the correct welcome page.

推荐答案

使用它来添加诸如 cssjavascriptimages 之类的资产.. 进入刀片文件.

Use this to add assets like css, javascript, images.. into blade file.

对于 CSS,

<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css" >

<link href="{{ URL::asset('css/app.css') }}" rel="stylesheet" type="text/css" >

对于 JS,

<script type="text/javascript" src="{{ asset('js/custom.js') }}"></script>

 <script type="text/javascript" src="{{ URL::asset('js/custom.js') }}"></script>

对于图像,

{{ asset('img/photo.jpg'); }}

这是文档

或者,如果你拉取了 laravel 4.2 中默认的 composer 包 illuminate/html 那么你可以像下面这样使用,在 laravel 5. 你必须手动拉包.

Alternatively, if you pulled the composer package illuminate/html which was come as default in laravel 4.2 then you can use like below, In laravel 5. you have to manually pull the package.

{{ HTML::style('css/style.css') }}

这是一个示例.

这篇关于Laravel 5 找不到 css 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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