Laravel资产()链接不正确
我正在使用“公共”文件系统驱动程序,我将文件存储在:Laravel资产()链接不正确,laravel,Laravel,我正在使用“公共”文件系统驱动程序,我将文件存储在: PROJECT\u ROOT/storage/app/public/message\u文件 但我也可以从这里访问它们(因为我创建了一个符号链接): PROJECT\u根目录/公共/存储/消息\u文件 然后,我尝试使用asset()helper获取指向该文件的链接,它会收到如下路径: 消息文件/gwYRplTEyX9O3Z1sOYXxk2C3ZfLVSiIZF93nZbjz.txt 并返回: http://localhost/message_f
PROJECT\u ROOT/storage/app/public/message\u文件
但我也可以从这里访问它们(因为我创建了一个符号链接):
PROJECT\u根目录/公共/存储/消息\u文件
然后,我尝试使用asset()helper获取指向该文件的链接,它会收到如下路径:
消息文件/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'),
],
],
];
如果您想使用资产访问存储。你必须运行这个命令
php-artisan-storage:link
然后您可以在资产中添加存储,如asset(storage/your/path)
我希望这有帮助将asset()
指向公共根目录是正常的,更改它可能会产生副作用
您可能正在寻找。我已经创建了一个链接,但问题是我不想手动将“存储”添加到asset()helper使用的每个路径中,如果您知道我的意思,我想为所有链接全局添加它。@您需要在您的路径中附加应用程序。您能给我举个例子吗?我不确定我是否知道你的意思。