Create New Post

Laravel MCQs - 1

  1. Which of the following is a correct way to define a route for a GET request in Laravel?

A) Route::get('/profile', 'ProfileController@show');

B) Route('/profile', 'ProfileController@show')->get();

C) Route('/profile')->get('ProfileController@show');

D) Route::show('/profile', 'ProfileController')->get();

Answer: A) Route::get('/profile', 'ProfileController@show');

  1. What is the purpose of Laravel's Query Builder?

A) To manage authentication

B) To construct SQL queries programmatically

C) To define database migrations

D) To generate HTML forms

Answer: B) To construct SQL queries programmatically

  1. Which directory contains the configuration files in a Laravel project?

A) config/

B) resources/views/

C) app/Http/

D) database/

Answer: A) config/

  1. What is the default database connection used in Laravel?

A) mysql

B) sqlite

C) postgresql

D) mongodb

Answer: A) mysql

  1. In Laravel, what is the purpose of the artisan serve command?

A) To serve static assets like CSS and JavaScript files

B) To serve the application using the built-in PHP web server

C) To run database migrations

D) To compile Blade templates

Answer: B) To serve the application using the built-in PHP web server

  1. Which of the following is not a valid session driver supported by Laravel?

A) file

B) database

C) cookie

D) redis

Answer: C) cookie

  1. What is the purpose of the php artisan make:model command in Laravel?

A) To create a new database migration

B) To create a new controller

C) To create a new model class

D) To create a new middleware

Answer: C) To create a new model class

  1. Which of the following is true about Laravel's Blade templating engine?

A) It is used for database migrations

B) It supports inheritance and sections

C) It is primarily used for routing

D) It is a JavaScript framework

Answer: B) It supports inheritance and sections

  1. What is the purpose of Laravel's env() function?

A) To execute SQL queries

B) To define environment-specific configuration

C) To create new artisan commands

D) To render Blade templates

Answer: B) To define environment-specific configuration

  1. Which of the following is NOT a valid way to access session data in Laravel?

A) Session::get('key');

B) $request->session()->get('key');

C) session('key');

D) $_SESSION['key'];

Answer: D) $_SESSION['key'];

Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

80450