@jaspal ensure you are using the ‘UseFactory’ trait in the model you’ve created the factory for
Aug 18, 2022
8
Level 10
factory error
This is the factory code
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Project>
*/
class ProjectFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'title' => $faker->sentence,
'description' => $faker->paragraph
];
}
}
when i run this with tinker ,
factory('App\Models\project')->make()
PHP Error: Call to undefined function factory() in C:\laragon\www\birdboard-testeval()'d code on line 1
Level 51
Convert your factory to be
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Project>
*/
class ProjectFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'title' => fake()->sentence,
'description' => fake()->paragraph
];
}
}
And call it like
App\Models\Project::factory()->make()
1 like
Please or to participate in this conversation.