What is custom Artisan commands in Laravel?
Why Interviewers Ask This
This is a differentiating question used for senior and lead roles. Interviewers want to see if you can explain not just what happens, but why — and what the trade-offs are in different approaches.
Answer
Custom Artisan commands extend the CLI with application-specific commands. Generate: php artisan make:command GenerateReport. The command class defines a $signature (command name and arguments/options): protected $signature = "report:generate {type} {--format=csv : Output format}". The $description is shown in php artisan list. The handle() method contains the logic. Access arguments: $this->argument("type"). Options: $this->option("format"). Output: $this->info("Done!"), $this->error("Failed!"), $this->table($headers, $rows), $this->progressBar(100). Ask user input: $this->ask("Enter name"), $this->confirm("Are you sure?"). Call from code: Artisan::call("report:generate", ["type" => "monthly"]).
Pro Tip
If you're unsure about a detail, say so honestly and explain your reasoning. Interviewers respect candidates who can think through uncertainty rather than bluffing.
Previous
What is the difference between load() and with() in Eloquent?
Next
What is Service Container advanced binding techniques?