我正在尝试生成一个假图像来填充播种机数据。
我用这个创建了一个播种机:
$this->faker->image(storage_path('app/public/products'), 500, 500)
当我尝试通过 Laravel Nova 访问它们以查看它们时,我得到了这种 URL:http://localhost/storage/var/www/html/storage/app/public/products/c8831002794cc55fe046c5e2b65794d4.png
在数据库中它被保存为:/var/www/html/storage/app/public/products/c8831002794cc55fe046c5e2b65794d4.png
知道我做错了什么吗?
见方法签名为image()
:
function image(
?string $dir = null,
int $width = 640,
int $height = 480,
?string $category = null,
bool $fullPath = true,
bool $randomize = true,
?string $word = null,
bool $gray = false,
string $format = 'png'
)
设置 $fullPath
到 false
将解决您的问题:
$this->faker->image(storage_path('app/public/products'), 500, 500, null, false)
试试这个:
$this->faker->image('app/public/products',400,300, null, false)
如果你有意见那么:
<img src="/my/path/{{ $item->image}}" >