2017-07-13 71 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