然后将创建下一个文件:app/Console/Commands/FilesLinkCommand.php 打开它,改变一些东西: 1.更好的命令签名:protected $signature = 'files:link'; 1.命令说明:protected $description = 'Create symlink link for files'; 1.命令代码,update方法handle():
public function handle(): void
{
// check if exists public/storage
if ( file_exists(app()->basePath('public/storage/')) ) {
$this->error("Symlink exists!");
exit(0);
}
// check if exists storage/app/public
if ( !file_exists(storage_path('app/public')) ) {
$this->error("Storage folder [app/public] not exists!");
exit(0);
}
// actually, we can create folders if not exists
// using mkdir() php function, or File::makeDirectory()
// but the second one still uses mkdir() behind the scene
app()->make('files')
->link(storage_path('app/public'), rtrim(app()->basePath('public/storage/'), '/'));
$this->info("Symlink created!");
}
2条答案
按热度按时间jtoj6r0c1#
Lumen/Laravel创建符号链接的方法:
然后将创建下一个文件:
app/Console/Commands/FilesLinkCommand.php
打开它,改变一些东西:
1.更好的命令签名:
protected $signature = 'files:link';
1.命令说明:
protected $description = 'Create symlink link for files';
1.命令代码,update方法handle():
这就是我们需要的!
使用:
php artisan files:link
如果第一次运行命令时,您将看到消息
Symlink created
,下次将更改为Symlink exists!
php函数symlink()可以做同样的事情
shyt4zoc2#
首先,请确认
storage/app/public
文件夹存在。如果不存在,请创建一个新文件夹。然后运行:
然后,将文件移动到
storage/app/public
现在,您应该能够访问如下资产:
”