I am unable Model Factory in Laravel Tinker.
//ItemFactory.php
class ItemFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Item::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => $this->faker->name,
'slug' => $this->faker->slug(5, true),
'code' => $this->faker->words(5, true),
'description' => $this->faker->sentence,
'price' => $this->faker->randomNumber(1000, 10000),
'size' => $this->faker->randomElement(['Small', 'Medium', 'Large',]),
];
}
}
Inside Tinker
>>> factory(App\Item::class)->create();
It throws me an error:
PHP Fatal error: Call to undefined function factory() in Psy Shell code on line 1
Illuminate\Database\Eloquent\Factories\HasFactory
In laravel 8 it's by default imported when make model using command – Wriggler