在 laravel 中植入假图像

问题描述 投票:0回答:2

我正在尝试生成一个假图像来填充播种机数据。

我用这个创建了一个播种机:

$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

知道我做错了什么吗?

laravel laravel-nova faker
2个回答
0
投票

方法签名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'
)

设置 $fullPathfalse 将解决您的问题:

$this->faker->image(storage_path('app/public/products'), 500, 500, null, false)

0
投票

试试这个:

$this->faker->image('app/public/products',400,300, null, false) 

如果你有意见那么:

<img src="/my/path/{{ $item->image}}" >
© www.soinside.com 2019 - 2024. All rights reserved.