2017-07-13 32 views
0

我使用的「公共」 fiilesystem司機和我將文件存儲在:Laravel資產()不正確的鏈接

PROJECT_ROOT/storage/app/public/message_files

但我也可以從這裏訪問它們(因爲我已經創建了一個符號鏈接):

PROJECT_ROOT/public/storage/message_files

然後我嘗試用資產()輔助,以獲得一個鏈接到該文件,並收到類似這樣的路徑:

message_files/gwYRplTEyX9O3Z1sOYXxk2C3ZfLVSiIZF93nZbjz.txt

和回報:

http://localhost/message_files/gwYRplTEyX9O3Z1sOYXxk2C3ZfLVSiIZF93nZbjz.txt

正如你所看到的,有一個在URL沒有 「存儲」 目錄下,這樣的鏈接是不正確。我的問題是:我們可以設置任何設置,以便「存儲」目錄不被省略?

這裏是我的filesystems.config:

<?php 

return [ 

    /* 
    |-------------------------------------------------------------------------- 
    | Default Filesystem Disk 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may specify the default filesystem disk that should be used 
    | by the framework. The "local" disk, as well as a variety of cloud 
    | based disks are available to your application. Just store away! 
    | 
    */ 

    'default' => env('FILESYSTEM_DRIVER', 'public'), 

    /* 
    |-------------------------------------------------------------------------- 
    | Default Cloud Filesystem Disk 
    |-------------------------------------------------------------------------- 
    | 
    | Many applications store files both locally and in the cloud. For this 
    | reason, you may specify a default "cloud" driver here. This driver 
    | will be bound as the Cloud disk implementation in the container. 
    | 
    */ 

    'cloud' => env('FILESYSTEM_CLOUD', 's3'), 

    /* 
    |-------------------------------------------------------------------------- 
    | Filesystem Disks 
    |-------------------------------------------------------------------------- 
    | 
    | Here you may configure as many filesystem "disks" as you wish, and you 
    | may even configure multiple disks of the same driver. Defaults have 
    | been setup for each driver as an example of the required options. 
    | 
    | Supported Drivers: "local", "ftp", "s3", "rackspace" 
    | 
    */ 

    'disks' => [ 

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

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

     's3' => [ 
      'driver' => 's3', 
      'key' => env('AWS_KEY'), 
      'secret' => env('AWS_SECRET'), 
      'region' => env('AWS_REGION'), 
      'bucket' => env('AWS_BUCKET'), 
     ], 

    ], 

]; 

在此先感謝!

回答

2

這是正常的,asset()指向公共根和改變,這將可能有副作用。

您可能正在尋找Storage::url()

0

如果你想訪問你的存儲資產。你必須運行命令

php artisan storage:link,那麼你可以像asset(storage/your/path)

我希望這有助於資產增加存儲

+0

我已經創建了一個鏈接,但事情是我不想手動添加「存儲」到資產()助手使用的每一個路徑,我想爲全部鏈接添加它,如果你知道什麼我的意思是。 – Razip

+0

@你需要在你的路徑中附加應用程序 –

+0

你能告訴我一個例子嗎?我不確定我是否知道你的意思。 – Razip