Skip to content
Advertisement

Unable to use Laravel Factory in Tinker

I am unable Model Factory in Laravel Tinker.

//ItemFactory.php

JavaScript

Inside Tinker

JavaScript

It throws me an error:

PHP Fatal error: Call to undefined function factory() in Psy Shell code on line 1

Advertisement

Answer

After going through the documentation of Model Factory, there were major changes in Laravel 8 version.

For using Model Factory anywhere inside Laravel 8:

  1. Inside Model, we need to import the IlluminateDatabaseEloquentFactoriesHasFactory trait

  2. New command to implement the factory

JavaScript
User contributions licensed under: CC BY-SA
3 People found this is helpful
Advertisement