我将 laravel 与 laragon 一起使用,一切正常,除了当我上传图像时它们返回404
,并且public/storage
是空的,但是storage/app/public
有文件,也public/public
有文件,所以它在公共文件夹中创建了一个错误的公共文件夹,我确实运行php artisan storage:link command
了我说它创建了我可以在编辑器中看到的存储链接,但是文件转到public/public
而不是public/storage
,我怎样才能让它工作?我想这是 laragon 的问题,因为它可以在其他环境中使用,而且我使用“命名”url 运行我的网站:myproject.test,并且我使用 apache2 作为 Web 服务器,请帮助修复它
问问题
1469 次
1 回答
3
如果你在linux上,你可以使用
ln -s [source] [virtual]
创建虚拟链接。在 Windows 上,您可以使用
mklink /j [virtual] [source]
做同样的事情。
请注意,您可能需要使用完整路径来创建链接。我在 laragon 上使用这种方法并且它有效。如果符号链接转到所需的文件夹,请在创建符号链接后双击链接检查它是否有效。如果没有,说明配置有问题。
奖金
我创建了一个控制台命令来自动化事情,也许你可以使用它:
用法:php artisan install:symlink
<?php
namespace App\Console\Commands;
use Illuminate\Console\Command;
class installSymlink extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'install:symlink';
/**
* The console command description.
*
* @var string
*/
protected $description = 'This artisan command installs pinpacker symlinks';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
//
$links = ["./public/thumbnails","./public/resized"];
$folders = ["./storage/app/public/thumbnails/","./storage/app/public/resized/"];
chdir(base_path());
try {
if (strtoupper(substr(PHP_OS, 0, 3)) === 'WIN') {
foreach($links as $i => $link){
$command = 'mklink /j "' . str_replace('/', '\\', $link) . '" "' . str_replace('/', '\\', $folders[$i]) . '"';
echo $command."\n";
exec($command);
}
} else {
foreach($links as $i => $link){
$command = 'ln -s ' . realpath($folders[$i]) . ' ' . $link;
echo $command ."\n";
exec($command);
}
}
printf("Symlinks created.\n");
} catch (Exception $e) {
printf($e->getMessage());
print_r($e);
}
}
}
于 2018-04-06T08:13:30.690 回答