faker image laravel 8
use Faker\Generator as Faker; $factory->define(Product::class, function (Faker $faker) { return [ 'amount' => $faker->randomFloat(2, 0, 10000), 'image' => $faker->image('public/storage/images',640,480, null, false), ]; });
Here is what the above code is Doing:
1. We’re using the factory() helper to define a new factory.
2. We’re telling the factory that we want to create a Product model.
3. We’re using the Faker library to generate fake data for the Product model.
4. We’re telling the factory that we want to create a Product model with the following fields:
– amount: a random float between 0 and 10000
– image: a random image from the public/storage/images directory