Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

davy_yg's avatar
Level 27

random image

Is it possible to seed my database by random dummy image?

What kind of image would that be?

0 likes
8 replies
Sergiu17's avatar
// image 100x100
$faker->imageUrl(100, 100);
1 like
davy_yg's avatar
Level 27

I wonder if this is the only reference for seeder:

https://laravel.com/docs/5.6/seeding

I wonder how to seed integer random data or only limited integer from 1 up to 3 for example. and what about image?

Why use $faker? In the reference they use:

    DB::table('banks')->insert([            
        'bank_name' => str_random(10),
        'bank_owner' => str_random(10),
        'bank_pin' => str_random(10),
        'bank_status' => str_random(10),
    ]);

Should I put

'bank_pic' => $faker->imageUrl(100, 100),

for example?

Sergiu17's avatar

@davy_yg this is fake data, so, faker is created exactly for this. Other alternatives are

'image' => 'https://placeimg.com/100/100/any?' . rand(1, 100),

or

'image' => 'http://via.placeholder.com/100x100'

To seed integer random data or limited integers, it depends on the situation.

1 like
davy_yg's avatar
Level 27

let say the column name is bank_pic and the location - localhost/eliteshop/images :

'bank_pic' => 'localhost/eliteshop/images'

Will this code create images? How do they know the image size?

If I use this code

'bank_pic' => $faker->imageUrl(100, 100),

How do they know the location of the image file? and will the images will actually be created?

topvillas's avatar

Fetch the files in the folder, choose a random file.

Sergiu17's avatar

@davy_yg you don't need to store real images in localhost/eliteshop/images

$faker->imageUrl(100,100)

will generate an url for the images.

How do they know the location of the image file?

// this variable is going to have a random image url from fake sites
// something like this: https://lorempixel.com/100/100/?39966
$bank->bank_pic

and will the images will actually be created?

No, you have full url which references on remote servers for images.

Please or to participate in this conversation.