I want to install laravel in shared hosting and I followed the steps here https://stackoverflow.com/a/28449523 but my asset path doesn't include the public directory

而不是这个

<link href='http://example.com/public/assets/css/style.css' type='text/css' media='all' />

I'm getting this

<link href='http://example.com/assets/css/style.css' type='text/css' media='all' />

如何在不更改任何核心类的情况下更改资源文件夹的目录(将公共资源添加到assets资源 )?

推荐答案

Before Laravel 5.7.14

Take a look at Illuminate\Routing\UrlGenerator class and its asset($path, $secure = null) method. This class is being put to container by url key. What you can do is:

  1. Add your own class, extending UrlGenerator;
  2. Add asset($path, $secure = null) method to your own class, making it return whatever you need;
  3. Create a service provider and register it in config/app.php;
  4. 在服务Provider 的register()方法中,绑定新类

这样,您根本不需要接触核心文件,而且您的Laravel应用程序仍然是更新友好的.

Update for Laravel 5.7.14 and later

As other answers state, there is the ASSET_URL .env option, which makes it much easier to change the public path. Laravel introduced it in Laravel 5.7.14, which was released about 3 years after my original answer.

Laravel相关问答推荐

Laravel FAKER语法

Laravel - 出于某种原因,max 打破了我的查询

mysql 加入 ON 和 AND 到 laravel eloquent

laravel 关系集合上的自定义排序

Blade引擎:打印三重花括号

Laravel 中的 index()" 是什么意思?

Laravel 5.2 中的正则表达式验证

无法安装 Laravel 包 - 干预图像

SQLSTATE [01000]:警告:1265 列的数据被截断(truncated)

Eloquent 的 Model::query() 是什么意思?

在 AWS 上找不到 Laravel 5 类Collective\Html\HtmlServiceProvider

Laravel 5.2 身份验证不起作用

在 laravel 6.0 中未定义命令ui

Laravel Eloquent 模型中的字段

Guzzle 返回流空体而不是 json 体

我在哪里放置可以显示 Flash 消息的 Laravel 4 辅助函数?

Composer RuntimeException - 无法加载软件包 mews/purifier

如何判断是否在laravel中使用了分页

无法在控制器的构造函数上调用 Auth::user()

laravel - 无法在控制器构造函数中获取会话