Answer the question
In order to leave comments, you need to log in
How to fix "Class not found" error?
I have laravel code.
testseeder.php
<?php
namespace Database\Seeders;
use App\Models\Myuser;
use Illuminate\Database\Seeder;
class TestSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Myuser::factory()->count(100)->create();
}
}
<?php
namespace Database\Factories;
use App\Models\Myuser;
use App\Models\User;
use Illuminate\Database\Eloquent\Factories\Factory;
class TestFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'lastname' => $this->faker->name(),
'firstname' => $this->faker->firstNameMale(),
'email' => $this->faker->email(),
'phone' => $this->faker->e164PhoneNumber(),
'balance' => $this->faker->name(),
'package' => $this->faker->name(),
'notification' => $this->faker->name(),
'img' => $this->faker->colorName(),
'password' => $this->faker->sha256(),
'ip' => $this->faker->sha1(),
'created_at' => $this->faker->dateTime(),
'updated_at' => $this->faker->dateTime(),
];
}
}
php artisan db:seed --class=TestSeeder
Class 'Database\Factories\MyuserFactory' not found
Answer the question
In order to leave comments, you need to log in
Try to be a little more careful, I'll give you a hint: you are trying to call a class factory (MyuserFactory) in the seeder, which you don't have, but have TestFactory. So we need to change...
Rename TestFactory to MyuserFactory. Your model name is Myuser and not Test. See how the factory() method works. It takes the name of the model + 'Factory' = the name of the class that is used next.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question