为什么无法在刀片模板中获得CSS资源的完整路径? [英] Why I can't obtain the complete path of a CSS resource in a blade template?
问题描述
我在Laravel非常陌生.我正在使用Laravel 5.4应用程序,使用刀片检索CSS资源的compl URL时遇到以下问题.
I am very new in Laravel. I am working on a Laravel 5.4 application and I have the following problem using blade to retrieve the comple URL of a CSS resource.
这是我的 app.blade.php 文件,代表我所有视图的模板:
This is my app.blade.php file representing the template of all my views:
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<!--<link href="/css/app.css" rel="stylesheet">-->
<!--<link href="{{ URL::asset('css/app.css') }}" rel="stylesheet" type="text/css" >-->
<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css" >
<link rel="stylesheet" href="//maxcdn.bootstrapcdn.com/font-awesome/4.7.0/css/font-awesome.min.css">
<script src="/js/app.js"></script>
</head>
<body>
<div class="container" style="width: 60%; margin-bottom: 50px;">
@yield('content')
</div>
@yield('footer')
</body>
</html>
如您所见,关注此SO帖子: Laravel 5找不到CSS文件
As you can see, folloing this SO post: Laravel 5 not finding css files
我正在以这种方式定义此CSS资源:
I am defining this CSS resource in this way:
<link href="{{ asset('css/app.css') }}" rel="stylesheet" type="text/css" >
检索 http://localhost/HotelRegistration/public/css/app正确位置的.css 资源.
to retrieve the http://localhost/HotelRegistration/public/css/app.css resource from the correct place.
问题在于以这种方式打开类似 http://localhost/HotelRegistration/public/registration的URL
The problem is that doing in this way opening an URL like http://localhost/HotelRegistration/public/registration
我仍然在生成的页面(该页面)中获得错误的CSS链接:
I still obtain the wrong CSS link in the generated page, this one:
<link href="/css/app.css" rel="stylesheet">
通过这种方式,我希望获得正确的 http://localhost /HotelRegistration/public/css/app.css
Doing in this way I expected to obtain the correct one http://localhost/HotelRegistration/public/css/app.css
我还尝试使用此备用链接导入它:
I also tried to import it using this alternative link:
<link href="{{ URL::asset('css/app.css') }}" rel="stylesheet" type="text/css" >
但我获得了相同的结果.
but I am obtaining the same results.
怎么了?我想念什么?如何解决此问题并获取包括整个路径在内的CSS的正确URL?
What is wrong? What am I missing? How can I fix this issue and obtain the correct url of my CSS including the entire path?
推荐答案
首先,最好使用工匠服务:
First, it is a good idea to use artisan serve:
php artisan serve
这将减少很多头痛.如果您使用的是Mac,请尝试valet
.真的很好,很轻.
This will reduces a lot of headaches. If you are on a Mac, try valet
. It is really nice and light.
第二,您需要通过以下方式导入css:
Second you need to import css in following manner:
<link href="{!! asset('css/app.css') !!}" rel="stylesheet" type="text/css" >
我希望这可以解决您的问题.
I hope this solves your problem.
这篇关于为什么无法在刀片模板中获得CSS资源的完整路径?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!