This worked for me in Laravel 8.
The value of image
is the path on my local machine to store uploaded images in the client
directory. When I ran this--App\Models\Client::factory()->create()
-- in tinker an image was uploaded to the clients
directory, and the image file name was stored in the database (see below). image()
, I believe, requires five arguments.


<?php
namespace Database\Factories;
use App\Models\Client;
use Illuminate\Database\Eloquent\Factories\Factory;
class ClientFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Client::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
'email' => $this->faker->unique()->safeEmail,
'phone' => $this->faker->phoneNumber,
'image' => $this->faker->image('public/assets/images/uploaded/clients', 400, 300, null, false),
'address' => $this->faker->streetAddress,
'city' => $this->faker->city,
'state' => $this->faker->stateAbbr,
'zip' => $this->faker->postcode,
'country' => $this->faker->country,
'description' => $this->faker->paragraph
];
}
}