In Tinker I'm running User::factory()->count(10)->create()
Jun 17, 2022
3
Level 3
Class Faker\Factory not found in Laravel 9
I'm getting this error when trying to run a factory that is using faker:
PHP Error: Class "Faker\Factory" not found in ../vendor/laravel/framework/src/Illuminate/Database/DatabaseServiceProvider.php on line 93
I don't know if I have to install faker separately? I thought it was bundled in Laravel and can't seem to find anything that would indicate otherwise.
My factory class:
namespace Database\Factories;
use App\Models\User;
use Illuminate\Support\Str;
use Illuminate\Database\Eloquent\Factories\Factory;
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'first_name' => $this->faker->firstName,
'last_name' => $this->faker->lastName,
'phone' => $this->faker->unique()->numerify('###-###-####'),
'email' => $this->faker->unique()->safeEmail,
'role_id' => rand(1,4),
'remember_token' => Str::random(10),
];
}
I'm not requiring anything additional in my composer.json file. My environment is set to local.
Please or to participate in this conversation.