LARAVEL Technology & Digital Applications 3 — Questions and Answers
Question 1: Which Laravel artisan command generates a new middleware class?
- php artisan make:filter
- php artisan make:middleware (Correct answer)
- php artisan make:guard
- php artisan make:pipe
Correct answer: php artisan make:middleware
`php artisan make:middleware` scaffolds a new middleware class in the `app/Http/Middleware` directory.
Question 2: In Laravel's service container, what is 'binding' used for?
- Linking two database tables
- Registering how to resolve an interface or class (Correct answer)
- Attaching event listeners to models
- Connecting to a WebSocket server
Correct answer: Registering how to resolve an interface or class
Binding tells the service container which concrete implementation to use when an interface or abstract class is requested.
Question 3: What does `php artisan migrate:fresh` do differently from `php artisan migrate:refresh`?
- Fresh rolls back migrations; refresh drops all tables
- Fresh drops all tables and re-runs migrations; refresh rolls back then re-runs (Correct answer)
- Fresh only runs pending migrations; refresh re-runs all
- There is no functional difference
Correct answer: Fresh drops all tables and re-runs migrations; refresh rolls back then re-runs
`migrate:fresh` drops every table (ignoring migration history), while `migrate:refresh` uses the `down()` methods to roll back.
Question 4: Which Laravel class would you extend to create a custom Artisan command?
- Illuminate\Console\Task
- Illuminate\Console\Command (Correct answer)
- Illuminate\Console\Kernel
- Illuminate\Console\Schedule
Correct answer: Illuminate\Console\Command
All custom Artisan commands extend `Illuminate\Console\Command` and define their signature and handle method.
Question 5: In Laravel, what is the role of the `AppServiceProvider`?
- Handles HTTP request authentication
- Bootstraps application services and bindings on startup (Correct answer)
- Defines all API routes
- Manages database connection pooling
Correct answer: Bootstraps application services and bindings on startup
`AppServiceProvider` is a central place to register service container bindings and perform bootstrap logic when the app starts.
Question 6: Which Laravel validation rule ensures a field's value exists in a specific database table column?
- unique
- exists (Correct answer)
- in
- foreign
Correct answer: exists
The `exists:table,column` rule verifies the submitted value is present in the given database table column.
Question 7: What is the primary purpose of Laravel Horizon?
- Monitoring and managing Redis-backed queues via a dashboard (Correct answer)
- Providing real-time WebSocket broadcasting
- Managing scheduled Artisan commands
- Handling HTTP load balancing
Correct answer: Monitoring and managing Redis-backed queues via a dashboard
Laravel Horizon provides a beautiful dashboard and real-time monitoring for Laravel's Redis-driven queue workers.
Which Laravel artisan command generates a new middleware class?