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

Fathom Analytics | Fast, simple and privacy-focused website analytics. Fathom Analytics | Fast, simple and privacy-focused website analytics.
Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future. Achieve superior email deliverability with ToastMail! Our AI-driven tool warms up inboxes, monitors reputation, and ensures emails reach their intended destination. Sign up today for a spam-free future.
Community Partners