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.
使用它来添加诸如 css
、javascript
、images
之类的资产.. 进入刀片文件.
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') }}
这是一个示例.