使用 faker 库在数据库中插入图像

Insert image in database using faker library

工厂Class

$factory->define(Product::class, function (Faker $faker) {
    return [
        'image' => url("/images/{$faker->image('public/storage/images',640,480, null, false)}")
    ];
});

在这个命令之后

php artisan db:seed

用该字符串填充的数据库图像列

http://localhost/images/a1af4cb757aef7f6b181dfb978228767.jpg"

当我在浏览器上搜索 url 时,我得到 "Unable to connect" 错误

你需要在 link 之前添加 storage images/image_name 才能像这样

http://localhost/storage/images/a1af4cb757aef7f6b181dfb978228767.jpg

Make sure that you run php artisan storage:link