Learn Laravel MCQs
Prepare Laravel MCQs (Multiple choice Questions) for exam and job interviews.
What is the command to create a new Laravel project?
1) composer create-project --prefer-dist laravel/laravel projectName
2) laravel new projectName
3) php artisan new projectName
4) create-project laravel/laravel projectName
Answer : composer create-project --prefer-dist laravel/laravel projectName
How do you create a new database connection in Laravel?
1) Add it to config/database.php
2) Add it to .env file
3) Add it to config/app.php
4) Add it to app/Providers
Answer : Add it to config/database.php
What is the purpose of the `config/cache.php` file?
1) Store cache configuration
2) Store application configuration
3) Store database configuration
4) Store routing configuration
Answer : Store cache configuration
How can you send a raw SQL query in Laravel?
1) DB::raw()
2) DB::query()
3) DB::execute()
4) DB::run()
Answer : DB::raw()
What is the command to create a new event subscriber in Laravel?
1) php artisan make:subscriber
2) artisan create:subscriber
3) make:subscriber
4) create:subscriber
Answer : php artisan make:subscriber
How do you define a fallback route in Laravel?
1) Route::fallback()
2) Route::default()
3) Route::catchAll()
4) Route::fallbackRoute()
Answer : Route::fallback()
How do you define an access control middleware in Laravel?
1) Route::middleware("auth")
2) Route::auth()
3) middleware("auth")
4) auth()->middleware()
Answer : Route::middleware("auth")
What is the command to create a new API controller in Laravel?
1) php artisan make:controller Api/ControllerName
2) artisan create:controller Api/ControllerName
3) make:controller Api/ControllerName
4) create:controller Api/ControllerName
Answer : php artisan make:controller Api/ControllerName
How can you generate a new migration file with a timestamp in Laravel?
1) php artisan make:migration create_table_name
2) php artisan make:migration create_table_name --timestamp
3) php artisan make:migration create_table_name --create
4) php artisan migrate:create
Answer : php artisan make:migration create_table_name
What is the purpose of the `php artisan serve` command?
1) Run a local development server
2) Migrate the database
3) Clear cache
4) Install dependencies
Answer : Run a local development server