Best WordPress Hosting
 

How To Generate and Use Fake Records with Laravel Model Factories

via kinsta.com => original post link

Testing is essential to web development. Laravel Model factories define database records in a predictable and easily replicable way so that your app tests are consistent and controlled. Model factories define a set of default attributes for each of your Eloquent models.

For example, if you’re making a blogging app allowing authors and moderators to approve comments before they go live, you’d need to test if the function works properly before deploying it to your users. All this requires test data.

To test the blogging app described above, you need comments data to imitate and test your application’s functionality. Laravel allows you to do that without getting comments from actual users by using Laravel factories and Faker to generate fake data.