简体   繁体   English

在生产环境中调用资产不起作用 Laravel 8(共享主机)

[英]calling asset on production env didn't work Laravel 8 (shared hosting)

hello there I'm having trouble with calling my asset in the production environment this is how the structure of the folder你好,我在生产环境中调用我的资产时遇到了问题,这是文件夹的结构

  • Laravel/拉拉维尔/
    • storage贮存
    • ... ...
  • public_html/ public_html/
    • storage(a symlink that I created and working fine using, ln -sfn domains/sites.com/new/storage/app/public/posted-images/../public_html/)存储(我创建并使用的符号链接,ln -sfn domain/sites.com/new/storage/app/public/posted-images/../public_html/)
    • ... ...

and this is how I call the asset:这就是我所说的资产:

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

this is how my filesystem.php looks a like:这就是我的 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'),
       ],

and in.env I put:和 in.env 我把:

FILESYSTEM_DRIVER = public

So I found the solution like this: first I'm deleting the storage link that I created with n -sfn domains/sites.com/new/storage/app/public/posted-images/../public_html/所以我找到了这样的解决方案:首先我删除了我用 n -sfn domain/sites.com/new/storage/app/public/posted-images/../public_html/ 创建的存储链接

then, in filesystem.php change:然后,在 filesystem.php 更改:

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

to

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

after that, make a request to store function and it will create the storage folder in public_html.之后,请求存储 function,它将在 public_html 中创建存储文件夹。 Your old file maybe not gonna appear there so(file before you change the root to 'storage'), you can copy the data that not there from storage file in the domain.您的旧文件可能不会出现在那里(在将根更改为“存储”之前的文件),您可以从域中的存储文件中复制不存在的数据。

And the way i call the asset is the same as above.我调用资产的方式与上面相同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM