Category: Laravel, Laravel, PHP, PHP

I have a quiz app which has the standard questions and answers etc. I can do this by calling a seeder class: What if I want to create a quiz with a variable number of questions, answers and user responses?

What if I create an artisa n command to take in my arguments and pass them to my seeder?

In my case, I want to set default values if I don’t pass anything, so I did this for my number of questions and answers: This means I can call the following commands: As you can see the parameters -Q and — questions are equivalent and optional. Now in the handle function, we need to get the options for questions & answers, and run the seeder: Now I can access these class-level variables in the seeder, and write my seeder using those parameters.
Newsletter

Get the latest Laravel/PHP jobs, events and curated articles straight to your inbox, once a week

Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge. Glimpse streamlines Laravel development by seamlessly deploying GitHub pull requests to preview environments with the help of Laravel Forge.
Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Shirts painstakingly handcrafted by under-caffeinated developers. Shirts painstakingly handcrafted by under-caffeinated developers.
Community Partners