I have the public folder inside my laravel project and I have some js and css files inside it.

我正在使用ASSET函数,即使它引用公共文件夹,我的文件也不会加载到页面上.

我用这段代码加载(这只是一个例子,还有更多文件):

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

在浏览器的控制台上,我得到如下信息:

加载资源失败:服务器响应状态为404(未找到)

Well, I tried to revert the last commit, but no success. Tried to change to URL::asset() function, nothing. Tried everything from the following link: http://laravel.io/forum/09-17-2014-problem-asset-not-point-to-public-folder?page=1 and success.

拜托,帮个忙?

谢谢

推荐答案

I was having same problem. This is due to moving of .htaccess file from public to root of the project in order to serve localhost/project rather than localhost/project/laravel. And needed to use public as well in the asset:

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

或者,从/Lightning/Foundation/helpers修改assets资源 功能.php

if (! function_exists('asset')) {
    /**
     * Generate an asset path for the application.
     *
     * @param  string  $path
     * @param  bool    $secure
     * @return string
     */
    function asset($path, $secure = null)
    {
        return app('url')->asset("public/".$path, $secure);
    }
}

前面的方法不是好方法.无论如何,如果有用于设置assets资源 路径的配置,这会更容易.

Laravel相关问答推荐

LaravelEloquent 的模型如何将值从控制器内部的函数传递到Render()

使用 laravel 根据当月显示注册用户列表

使用枢轴插入多对多时的Laravel问题

Laravel init 查询多种用途

在 laravel 4.2 中,用户 'root'@'localhost' 的 Laravel 访问被拒绝(使用密码:YES)

Laravel 不验证是否不需要字段

如何对有序的has many关系进行分页?

查询 Laravel Select WhereIn 数组

在 laravel 如何将额外的数据传递给 mutators 和 accessors

使用数据库中的值进行动态邮件配置 [Laravel]

Laravel 随机排序

调用未定义的方法 Maatwebsite\Excel\Excel::load()

如何从 laravel 中的现有数据库创建迁移

WhereNotExists Laravel Eloquent

Laravel 5.4 有时验证规则不起作用

Laravel 5 与 Postgresql

未找到列:1054 未知列 laravel

Laravel 中的单会话登录

Laravel 中的 isDirty() 是什么意思?

如何让 Laravel 将 View 的Content-Type标头返回为application/javascript?