TOPIC COLLECTION
Factories.
A collection of 8 practical ideas to make everyday Laravel work a little smoother.
08 TIPS01Factory CallbacksWhile using factories for seeding data, you can provide Factory Callback functions to perform some action after record is inserted.Factories02Generate Images with Seeds/factoriesDid you know that Faker can generate not only text values but also IMAGES? See avatar field here - it will generate 50x50 imageFactories03Override Values and Apply Custom Login to ThemWhen creating records with Factories, you can use Sequence class to override some values and apply custom logic to them.Factories04Using Factories with RelationshipsWhen using factories with relationships, Laravel also provides magic methods.Factories05Create Models without Dispatching Any EventsSometimes you may wish to update a given model without dispatching any events. You may accomplish this using the updateQuietly methodFactories06Useful for() MethodThe Laravel factory has a very useful for() method. You can use it to create belongsTo() relationships.Factories07Run Factories without Dispatching EventsIf you want to create multiple records using Factory without firing any Events, you can wrap your code inside a withoutEvents closure.Factories08Specify Dependencies in the Run() MethodYou can specify dependencies in the run() method of your seeder.Factories