Laravel 5.2:资产路径在服务器上不起作用 [英] Laravel 5.2: asset path not working on server

查看:54
本文介绍了Laravel 5.2:资产路径在服务器上不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的laravel 5.2应用程序无法从生产服务器上的public/css目录中获取样式表,但可以在本地计算机上获取样式表!

My laravel 5.2 app unable to fetch the stylesheet from the public/css directory on the production server but can fetch stylesheets on the local machine!

这是我链接文件的方式:

here is how I am linking my files:

<link href="{{asset('css/clock.css')}}" rel="stylesheet" media="all" />

我还尝试了一堆不同的方法:

I also tried bunch of different ways:

<link href="{{URL::asset('css/clock.css')}}" rel="stylesheet" media="all" />

OR:

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

但是服务器上没有任何作用!

but nothing worked on server!

但是它无法获取CSS!当我检查页面源代码时,它显示出其他链接的css文件..是否是因为我曾经重定向到网站的公共文件夹的".htaccess"文件?

but it is not able to fetch the css! when I check the page source, it shows me some other css file linked.. is it because of '.htaccess' file that I used to redirect to the public folder of my site?

您可以在在此处输入链接描述.

请帮助!

推荐答案

asset()助手将基本URL附加到您提供的路径中. 但是laravel将js,css和图像文件保存在 public 文件夹中,因此您需要添加以下公共路径:

The asset() helper prepends the base URL to the path you supply. But laravel keep js, css, and image files into public folder so you need to add public path like this:

href="public/{{ asset('css/style.css') }}.

而不是对此文件进行- vendor\laravel\framework\src\Illuminate\Foundation\helpers.php

function asset($path, $secure = null)
{
    if($_SERVER['HTTP_HOST']=='127.0.0.1:8000')
        return app('url')->asset($path, $secure);
    else
        return app('url')->asset('public/'.$path, $secure);
}

这篇关于Laravel 5.2:资产路径在服务器上不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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