Generate Images with Seeds/Factories

Did you know that Faker can generate not only text values but also IMAGES? See avatar field here - it will generate 50x50 image:

1$factory->define(User::class, function (Faker $faker) {
2 return [
3 'name' => $faker->name,
4 'email' => $faker->unique()->safeEmail,
5 'email_verified_at' => now(),
6 'password' => bcrypt('password'),
7 'remember_token' => Str::random(10),
8 'avatar' => $faker->image(storage_path('images'), 50, 50)
9 ];
10});

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord