Laravel asset()链接不正确

时间:2017-07-13 05:34:05

标签: laravel

我正在使用" public" fiilesystem驱动程序和我存储文件:

PROJECT_ROOT/storage/app/public/message_files

但是我也可以从这里访问它们(因为我已经创建了一个符号链接):

PROJECT_ROOT/public/storage/message_files

然后我尝试使用asset()帮助程序获取该文件的链接,并收到类似这样的路径:

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 个答案:

答案 0 :(得分:3)

asset()指向公共根是正常的,改变这种情况可能会产生副作用。

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

答案 1 :(得分:0)

如果您想使用资产访问您的存储空间。你必须运行命令

php artisan storage:link然后您可以在asset(storage/your/path)

等资产中添加存储空间

我希望这会有所帮助