【问题标题】:calling asset on production env didn't work Laravel 8 (shared hosting)在生产环境中调用资产不起作用 Laravel 8(共享主机)
【发布时间】:2022-01-03 12:03:22
【问题描述】:

你好,我在生产环境中调用我的资产时遇到问题,这是文件夹的结构

  • Laravel/
    • 存储
    • ...
  • public_html/
    • 存储(我创建的符号链接,使用 ln -sfn 可以正常工作 域/sites.com/new/storage/app/public/posted-images/../public_html/)
    • ...

这就是我对资产的称呼:

   <img src="{{ asset('storage/'.$posts->image)  }}" alt="" class="img-fluid">

这就是我的 filesystem.php 的样子:

'disks' => [

        'local' => [
            'driver' => 'local',
            'root' => storage_path('app'),
        ],

        'public' => [
            'driver' => 'local',
            'root' => storage_path('app/public'),
            'url' => env('APP_URL').'/storage',
            'visibility' => 'public',
        ],

       'links' => [
        public_path('storage') => storage_path('app/public'),
       ],

在 .env 中我放了:

FILESYSTEM_DRIVER = public

【问题讨论】:

    标签: php laravel laravel-blade


    【解决方案1】:

    所以我找到了这样的解决方案: 首先,我要删除使用 ln -sfn domain/sites.com/new/storage/app/public/posted-images/ ../public_html/ 创建的存储链接

    然后,在 filesystem.php 中更改:

    'public' => [
                'driver' => 'local',
                'root' => storage_path('app/public'),
                'url' => env('APP_URL').'/storage',
                'visibility' => 'public',
            ],
    

    'public' => [
                'driver' => 'local',
                'root' => 'storage',
                'url' => env('APP_URL').'/storage',
                'visibility' => 'public',
            ],
    

    之后,请求存储函数,它将在 public_html 中创建存储文件夹。您的旧文件可能不会出现在那里(在您将根更改为“存储”之前的文件),您可以从域中的存储文件夹中复制不存在的数据。

    而且我调用资产的方式和上面一样。

    【讨论】:

      猜你喜欢
      • 2023-03-23
      • 2013-04-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多