From the course: Building RESTful APIs in Laravel

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

Creating a model factory and seeder

Creating a model factory and seeder

From the course: Building RESTful APIs in Laravel

Start my 1-month free trial

Creating a model factory and seeder

- [Instructor] To test our API, we will need data. Yes, we could add it manually to the database but that would be too time consuming and simply annoying. Instead, we can use model factories and database seeders to do this work for us. Database seeding is the initial process of adding data to the database. We can use the already created database seeder class and use the DB Facade to insert the data into the petition stable like so. So we would use the DB Facade, call the tables static class on the petitions table, and call the insert function, which accepts an array of data. This array of data is the array of fields we want in our database. So in our case, the title fields which would be a random string, about 10 characters long, then we need the category field which will also be string, random, about 30 characters long. And then we would need the description and so on. But as you can see, this is quite…

Contents