PHP Laravel MCQ Questions & Answers
Laravel MCQs : This section focuses on "Laravel" PHP Framework. These Multiple Choice Questions (MCQ) should be practiced to improve the PHP Laravel skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. Which of the following is true about Laravel?
A. Laravel is an open-source PHP framework
B. Laravel is robust
C. Laravel is easy to understand
D. All of the above
View Answer
Ans : D
Explanation: Laravel is an open-source PHP framework, which is robust and easy to understand.
2. Command line interface used in Laravel is called?
A. composer
B. Artisan
C. Symphony
D. ORM
View Answer
Ans : B
Explanation: Command line interface used in Laravel is called Artisan.
3. ORM (Object Relational Mapper) and ActiveRecord implementation called?
A. Eloquent
B. Query Builder
C. Schema Builder
D. Blade Template
View Answer
Ans : A
Explanation: ORM (Object Relational Mapper) and ActiveRecord implementation called Eloquent.
4. Laravel uses ___________ to connect to an existing session and general-purpose cache
A. Queues
B. Cron
C. Redis
D. Command Bus
View Answer
Ans : C
Explanation: Laravel uses Redis to connect to an existing session and general-purpose cache. Redis interacts with session directly.
5. ______________ acts as a bridge between a request and a response.
A. Routing
B. Middleware
C. Namespaces
D. Request
View Answer
Ans : B
Explanation: Middleware acts as a bridge between a request and a response.
6. Which command is used to create Middleware?
A. php make:middleware <middleware-name>
B. php artisan middleware <middleware-name>
C. php middleware <middleware-name>
D. php artisan make:middleware <middleware-name>
View Answer
Ans : D
Explanation: Middleware can be created by executing the following command : php artisan make:middleware <middleware-name>
7. How many types of Middleware in Laravel?
A. 2
B. 3
C. 4
D. 5
View Answer
Ans : A
Explanation: There are two types of Middleware in Laravel : Global Middleware and Route Middleware.
8. The _______________ will run on every HTTP request of the application
A. Global Middleware
B. Route Middleware
C. Both A and B
D. None of the above
View Answer
Ans : A
Explanation: The Global Middleware will run on every HTTP request of the application, whereas the Route Middleware will be assigned to a specific route.
9. ________________ can be defined as a class of elements in which each element has a unique name to that associated class.
A. Routing
B. Cookie
C. Namespaces
D. Request
View Answer
Ans : C
Explanation: Namespaces can be defined as a class of elements in which each element has a unique name to that associated class.
10. Which keyword allows the developers to shorten the namespace?
A. extend
B. use
C. artisan
D. class
View Answer
Ans : B
Explanation: The use keyword allows the developers to shorten the namespace.
11. In the MVC framework, the letter 'C' stands for?
A. Cookie
B. Configuration
C. command prompt
D. Controller
View Answer
Ans : D
Explanation: In the MVC framework, the letter ‘C’ stands for Controller. It acts as a directing traffic between Views and Models. In this chapter, you will learn about Controllers in Laravel.
12. Execute the below command to create a new controller called?
php artisan make:controller UriController –plain
A. UrlController
B. pathController
C. UriController
D. routeController
View Answer
Ans : C
Explanation: Execute the below command to create a new controller called UriController.
php artisan make:controller UriController –plain
13. Cookie can be created by global cookie helper of Laravel.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: Cookie can be created by global cookie helper of Laravel. It is an instance of SymfonyComponentHttpFoundationCookie.
14. The cookie can be attached to the response using the ?
A. isCookie() method
B. withCookie() method
C. getCookie() method
D. putCookie() method
View Answer
Ans : B
Explanation: The cookie can be attached to the response using the withCookie() method. Create a response instance of IlluminateHttpResponse class to call the withCookie() method. Cookie generated by the Laravel are encrypted and signed and it can’t be modified or read by the client.
15. How many arguments cookie() method will take?
A. 2
B. 4
C. 1
D. 3
View Answer
Ans : D
Explanation: Cookie() method will take 3 arguments. First argument is the name of the cookie, second argument is the value of the cookie and the third argument is the duration of the cookie after which the cookie will get deleted automatically.
16. By default, all cookies generated by Laravel are encrypted and signed so that they can not be modified or read by the client.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: By default, all cookies generated by Laravel are encrypted and signed so that they can not be modified or read by the client.
17. Which method will automatically convert the array into appropriate json response?
A. application.json
B. json
C. routes
D. test
View Answer
Ans : B
Explanation: JSON response can be sent using the json method. This method will automatically set the Content-Type header to application/json. The json method will automatically convert the array into appropriate json response.
18. In MVC framework, the letter "V" stands for Value.
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : B
Explanation: In MVC framework, the letter “V” stands for Views. It separates the application logic and the presentation logic.
19. Which version introduces the concept of using Blade?
A. Laravel 2.1
B. Laravel 3.1
C. Laravel 4.1
D. Laravel 5.1
View Answer
Ans : D
Explanation: Laravel 5.1 introduces the concept of using Blade, a templating engine to design a unique layout.
20. Laravel uses the Blade @extends directive for defining the child elements
A. TRUE
B. FALSE
C. Can be true or false
D. Can not say
View Answer
Ans : A
Explanation: True, Laravel uses the Blade @extends directive for defining the child elements.
Discussion