Laravel Factory. InvalidArgumentException with message ‘Unable to locate factory with name [default] [App\Model].’

If you are using the Laravel factories to populate the database with fake elements, when you add a new factory, v.gr. in the “\database\factories\ModelFactory.php”, ant try to execute it with the tinker app

$ php artisan tinker
>>> factory(App\Contrato::class, 100)->create();

you can receive this error (for the “Contrato” model).

InvalidArgumentException with message 'Unable to locate factory with name [default] [App\Contrato].'

This could be a cache problem. You can resolve it executing the commands showed in this link.

php artisan clear-compiled
composer dump-autoload
php artisan optimize

Leave a comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.