Here are the main benefits of this package as provided in the readme:
- use the features you already love from Laravel factories (
- automatically create new class factories for specific or
- automatically import defined
statesfrom your Laravel factories
- and many more…
Here are some examples of how you might use the class-based factories provided by this package:
// Create a new record in the database $user = UserFactory::new()->create(); // Make a new model without peristing to the database $user = UserFactory::new()->make(); // Use a factory state $recipe = UserFactory::new() ->active() ->create(); // Relations $recipe = RecipeFactory::new() ->with(Group::class, 'group') ->with(Ingredient::class, 'ingredients') ->with(Ingredient::class, 'ingredients', 3) ->create();
You might be asking, “what is the benefit of using class-based factories?” The project’s readme mentions the following benefits of using this package:
- They give you much more flexibility on how to create your model instances.
- They make your tests much cleaner because you can hide complex preparations inside the class.
- They provide IDE auto-completion, which you do not have with Laravel factories.
You can learn more about this package, get full installation instructions, and view the source code on GitHub at christophrumpel/laravel-factories-reloaded.Filed in: News
- Backend Software Engineer (PHP Developer)
Austin TX, Bonita Springs FL
Certified eSupport Corp
- Backend PHP Developer
ABOUT YOU GmbH
- Full-Stack Engineer (Mid to Senior)
Remote (EST, CST)
- Senior Laravel Developer (AI Applications)
Remote from anywhere in the UK or from our London office
- Full Stack Engineer
Join 31,000+ others and never miss out on new tips, tutorials, and more.
Create Model Sequences With the Eloquent Sequencer Package
Eloquent Sequencer is a package by Gustavo R. Gentil for automatically sequencing your models when adding new records…
Tailwind CSS IntelliSense
The Tailwind team just shipped a new release of the Tailwind CSS IntelliSense plugin for VSCode that adds Tailwind-sp…