What is a Controller in Laravel?
Why Interviewers Ask This
Interviewers use this question to quickly assess whether a candidate has the foundational knowledge required for Laravel development. It reveals whether you understand the building blocks that more complex concepts rely on.
Answer
A Controller in Laravel handles the HTTP request logic — it sits between routes and models/views. Generate with php artisan make:controller UserController. Controllers live in app/Http/Controllers/. A resource controller (--resource flag) generates seven RESTful methods automatically: index (list all), create (show create form), store (save new), show (show one), edit (show edit form), update (save edits), destroy (delete). Register all seven with one line: Route::resource("users", UserController::class). Controllers can use constructor injection — Laravel's service container automatically resolves dependencies.
Pro Tip
This topic has Laravel-specific nuances that differ from general programming. Highlighting those nuances in your answer shows expertise rather than generic knowledge.