1.Bootstrap directory in Laravel is used to__________
1. Initialize a Laraval application
2. Call laravel library functions
3. Load laravel classes and models
4. Load the configuration files
Answer: Initialize a Laraval application
2. How to create a controller in laravel by cmd?
1. php artisan make:controller generate
2. php artisan make: generate controller contoller_name
3. php artisan make:controller –plain
4. php artisan make:request controller_name create
Answer: php artisan make:controller –plain
3. Interpolation of variable in laravel done using
1. {{}}
2. compact
3. helpers
4. None
Answer: {{}}
4. Which command is used to start laravel server?
1. php artisan project_name
2. artisan start-server
3. php artisan serve
4. php artisan start php
Answer: php artisan serve
5. Which one Laravel command line interface?
1. Composer
2. Php artisan
3. Git
4. CLI
Answer: Php artisan
6. Why does Laravel use the Blade Template Engine?
1. As a template
2. To simplify programming
3. For the view in MVC
4. For fun
Answer: For the view in MVC
7. View files in Laravel end in________–
1. .blade.php
2. .vue
3. .blade
4. .php
Answer: .blade.php
8. Which of the following function in Laravel checks that the desired table is exists in
the database or not?
1. hashTable()
2. hasTab()
3. hasTable()
4. None
Answer: hasTable()
9. What is Laravel?
1. Programming language
2. PHP framework
3. Code generator
4. none of the above
Answer: PHP framework
10. Where do we need to set database connection in Laravel?
1. Config.php
2. Setting.php
3. In seed files
4. .ENV file
Answer: .ENV file
11. Where is the routing file located in Laravel ?
1. urls/
2. routes/
3. vendors/
4. app/Http/
Answer: routes/
12. How to set a session data in Laravel?
1. $request->session()->put(‘key’, ‘value’);
2. $request->db->session(‘key’, ‘value’);
3. $request->session()->set(‘key’, ‘value’);
4. none
Answer: $request->session()->put(‘key’, ‘value’);
13. How to check current laravel version install your system?
1. php artisan check –version
2. php artisan make –version
3. php artisan –version
4. none of the above
Answer: php artisan –version
14. For what do the .env is used?
1. For running cron jobs
2. For setting environment variables
3. For tracking vendors
4. None of These
Answer: For setting environment variables
15. How to get current action name in Laravel?
1. request()->DB->getActionMethod()
2. request()->route()->getActionMethod()
3. request()->getActionMethod()
4. none of the above
Answer: request()->route()->getActionMethod()
16. Which command is used to create migrations in Laravel?
1. php artisan make:migration create_users_table
2. php artisan migration create_users_table
3. php artisan make:migrate create_users_table
4. none
Answer: php artisan make:migration create_users_table
17. What does ORM stands for in laravel?
1. object-related Modifier
2. overloaded-relational Mapping
3. object-Rotational Mechanisim
4. object-relational Mapping
Answer: object-relational Mapping
18. Composer is a tool for ______ in PHP.
1. Configuration
2. Dependency management
3. Interpolation
4. None of the above
Answer: Dependency management
19. Which class is used in Laravel to handle exceptions?
1. App\Exception\Handler
2. App\Exceptions\Handler
3. App\Exceptions\Handle
4. None of above
Answer: App\Exceptions\Handler
20. When was Laravel first released?
1. June 2011
2. June 2007
3. June 2009
4. None
Answer: June 2011
21. After running “artisan down”, The project will show the maintenance page. What
would be HTTP Status return Code?
1. 298
2. 503
3. 400
4. 254
Answer: 503
22. Where are all the Laravel Models stored at ?
1. Inside Laravel database
2. Within a server
3. Main app directory
4. None of the above
Answer: Main app directory
23. Which of the following methods are used in Database Migrations classes?
1. run() and delete()
2. save() and update()
3. execute() and rollback()
4. up() and down()
Answer: up() and down()
24. Who developed Laravel?
1. James Gosling
2. Rasmus Lerdorf
3. Taylor Otwell
4. Guido van Rossum
Answer: Taylor Otwell
25. What is the purpose of Laravel Blade Template Engine?
1. Make things harder
2. Increase workload for students
3. Beautify Laravel
4. Makes writing syntax easy and readable
Answer: Makes writing syntax easy and readable
26. What is the purpose of learning Web Programming?
1. To install computer programs
2. To create computer parts
3. To design the computer outlook
4. To talk to computers
Answer: To talk to computers
27. The vendor directory contains
1. Assets
2. Laravel Framework code
3. Third-party code
4. Configuration files
Answer: Third-party code
28. What type of way does Laravel use to get data from a database ?
1. Eloquent ORM and Query Builder
2. Eloquent ORM
3. Query Builder
4. None of the above
Answer: Eloquent ORM and Query Builder
29. Which one of the following command is used to create middleware in Laravel?
1. php artisan make: middleware
2. php arti make: middleware
3. php artisan: middleware
4. none of the above
Answer: php artisan make: middleware
30. What is Node JS?
1. Different version of the normal JavaScript
2. Special type of JavaScript language
3. JavaScript runtime environment that executes JavaScript code
4. None
Answer: JavaScript runtime environment that executes JavaScript code
1. Which method returns the average value of a given key ?
• average()
• avg()
• median()
• avg_val()
Answer: B
avg() method in laravel returns the average value of a given key
$average = collect([['foo' => 10], ['foo' => 10], ['foo' => 20], ['foo' => 40]])->avg('foo'); // 20
$average = collect([1, 1, 2, 4])->avg(); // 2
2. Bootstrap directory in Laravel is used to
• Initialize a Laraval application
• Call laravel library functions
• Load the configuration files
• Load laravel classes and models
Answer: A
3. Which artisan command is used to remove the compiled class file.
• clear-compiled
• clear compiled
• compiled:clear
• clear:all
Answer: clear-compiled
Syntax:
php artisan clear-compiled
4. Which method breaks the collection into multiple, smaller collections of a given size
• split()
• chunk()
• explode()
• break()
Answer: chunk() method in Laravel is used to breaks the collection into multiple, smaller collections of a
given size.
syntax:
$collection = collect([1, 2, 3, 4, 5, 6, 7]);
$chunks = $collection->chunk(4);
$chunks->toArray();
// [[1, 2, 3, 4], [5, 6, 7]]
5. Artisan command to flush the application cache:
• cache:flush
• cache:clear
• cache:forget
• cache:remove
Answer: cache:clear
6. The vendor directory contains
• Laravel Framework code
• Assets
• Third-party code
• Configuration files
Answer: The vendor directory of Laravel contains Third-party code.
7. Where is the routing file located in Laravel ?
• app/Http/
• routes/
• urls/
• vendors/
Answer: Routing file located in Laravel are location in routes directory.
8. View files in Laravel end in
• .blade.php
• .php
• .vue
• .blade
Answer: View files in Laravel end in .blade.php
9. Which of following command is used to create a symbolic link from "public/storage"
directory to "storage/app/public".
• storage:link
• link:public
• link:storage
• storage:link public/storage
Answer: storage:link is used to create a symbolic link from "public/storage" directory to "storage/app/public".
10. Which of following methods are used in database migrations classes?
• execute() and rollback()
• up() and down()
• run() and delete()
• save() and update()
Answer: up() and down()
11. For what do the .env is used?
• For setting environment variables
• For running cron jobs
• For tracking vendors
• None of These
Answer: For setting environment variables
12. Which directory contain “robot.txt” file ?
• app
• public
• config
• storage
Answer: public
13. Interpolation of variable in laravel done using
• compact
• {{}}
• helpers
Answer: {{}}
14. What is the HTTP Status Code for your website. When it is down for maintenance.
• 501
• 200
• 400
• 503
Answer: 503 is HTTP Status Code for your website when it is down for maintenance using artisan down command
15. __() in laravel used for
• Printing value
• For string translation
Answer: For string translation
16. Where do we need to set database connection in Laravel?
• config.php
• setting.php
• In seed files
• .ENV file
Answer: .ENV file
17. What is the minimum PHP version required to install Laravel 5.3?
• 7.1
• 5.6.4
• 5.3.2
• 5.4.3
Answer: 5.6.4
18. How to set a session data in Laravel?
• $request->db->session('key', 'value');
• $request->session()->set('key', 'value');
• $request->session()->put('key', 'value');
• None of These
Answer: $request->session()->put('key', 'value');
19. Who developed Laravel?
• Rasmus Lerdorf
• Taylor Otwell
• James Gosling
• Guido van Rossum
Answer: Taylor Otwell
20. How to create a controller in laravel by cmd?
• php artisan make: generate controller contoller_name
• php artisan make:controller generate
• php artisan make:controller --plain
• php artisan make:request controller_name create
Answer: php artisan make:controller --plain
21. What is the purpose of the app/Providers directory in a Laravel project?
• It stores views for the application
• It stores controllers for the application
• It stores routes for the application
• It stores classes that provide various services to the rest of the application
Answer: It stores classes that provide various services to the rest of the application
22. What is the purpose of the .env file in a Laravel project?
• It stores views for the application
• It stores routes for the application
• It stores environment-specific configuration for the application
• None of the above
Answer: It stores environment-specific configuration for the application
23. Which of the following is NOT a Laravel service container?
• $db
• $app
• $cache
• $request
Answer: $request
24. How can you define a new route in a Laravel application?
• By adding a new route to the routes/web.php file
• By adding a new route to the app/Routes/web.php file
• By adding a new route to the app/Routes/web.php file
• By adding a new route to the app/Http/Controllers/Route.php file
Answer: By adding a new route to the routes/web.php file
25. How can you display a view in a Laravel application?
• By using the view() helper function
• By using the render() method of the View class
• By using the display() method of the View class
• Both A and B options are right
Answer: Both A and B options are right
Q1. Which method is used to handle an incoming HTTP request in Laravel?
a) get()
b) post()
c) handle()
d) route()
Answer: d) route()
Q2. How can you define a route in Laravel?
a) Using the web middleware
b) Using the Route::define() method
c) Using the Route::get() method
d) Using the @route directive in Blade templates
Answer: c) Using the Route::get() method
Q3. Which of the following is true about route parameters in Laravel?
a) Route parameters are optional and can be omitted.
b) Route parameters are enclosed in curly braces {} in the route definition.
c) Route parameters are only available in the request query string.
d) Route parameters are automatically extracted from the request body.
Answer: b) Route parameters are enclosed in curly braces {} in the route definition.
Q4. How can you access route parameters in a Laravel controller method?
a) By using the Request::get() method
b) By using the request() helper function
c) By using the $request variable passed to the method
d) By using the Route::parameter() method
Answer: c) By using the $request variable passed to the method
Q5. Which method is used to return a JSON response in Laravel?
a) response()->json()
b) json()->response()
c) return new JsonResponse()
d) return json_response()
Answer: a) response()->json()
Q6. How can you redirect the user to a different URL in Laravel?
a) Using the redirect() function
b) Using the Response::redirect() method
c) Using the Route::redirect() method
d) Using the response()->redirect() method
Answer: a) Using the redirect() function
Q7. Which of the following middleware is used to verify if a user is authenticated in Laravel?
a) auth
b) web
c) middleware
d) guest
Answer: a) auth
Q8. What is the purpose of the csrf middleware in Laravel?
a) To prevent cross-site scripting (XSS) attacks
b) To verify that the request is not a cross-site request forgery (CSRF)
c) To encrypt the request data for enhanced security
d) To cache the response for faster retrieval
Answer: b) To verify that the request is not a cross-site request forgery (CSRF)
Q1. How do you define a route parameter in Laravel?
a) By enclosing the parameter in curly braces {} in the route definition.
b) By appending the parameter to the route URL using a question mark ?.
c) By using the Route::parameter() method.
d) By defining the parameter in the controller method signature.
Answer: a) By enclosing the parameter in curly braces {} in the route definition.
Q2. How can you access a route parameter value inside a route closure or controller method in Laravel?
a) By using the request()->parameter() method.
b) By using the Route::getParameter() method.
c) By using the $request object's route() method.
d) By using the Route::current()->parameter() method.
Answer: c) By using the $request object's route() method.
Q3. Which method is used to load a view in Laravel?
a) view()
b) loadView()
c) render()
d) make()
Answer: a) view()
Q4. How can you pass data to a view in Laravel?
a) By using the with() method on the view instance.
b) By using the compact() function.
c) By adding data as an array parameter to the view() function.
d) By using the @data directive in Blade templates.
Answer: a) By using the with() method on the view instance.
Q5. How can you share data with all views in Laravel?
a) By using the share() method on the view instance.
b) By adding data to the $GLOBALS array.
c) By using the View::share() method in a service provider.
d) By using the @shared directive in Blade templates.
Answer: c) By using the View::share() method in a service provider.
Q6. How can you attach headers to a response in Laravel?
a) By using the $response->headers->set() method.
b) By using the response()->header() function.
c) By using the response()->withHeaders() method.
d) By using the header() function outside of the response context.
Answer: c) By using the response()->withHeaders() method.
Q7. How can you attach cookies to a response in Laravel?
a) By using the $response->cookies->set() method.
b) By using the response()->cookie() function.
c) By using the response()->withCookies() method.
d) By using the setcookie() function outside of the response context.
Answer: b) By using the response()->cookie() function.
Q8. Which method is used to return a JSON response in Laravel?
a) response()->json()
b) json()->response()
c) return new JsonResponse()
d) return json_response()
Answer: a) response()->json()
Q9. How can you redirect the user to a different URL in Laravel?
a) By using the redirect() function.
b) By using the Response::redirect() method.
c) By using the Route::redirect() method.
d) By using the response()->redirect() method.
Answer: a) By using the redirect() function.
Q10. How can you redirect to a named route in Laravel?
a) By using the redirect()->toRoute() method.
b) By using the Route::redirectTo() method.
c) By using the response()->route() method.
d) By using the redirect()->route() method.
Answer: d) By using the redirect()->route() method.
Q11. How can you redirect to a controller action in Laravel?
a) By using the redirect()->toAction() method.
b) By using the Route::redirectAction() method.
c) By using the response()->action() method.
d) By using the redirect()->action() method.
Answer: d) By using the redirect()->action() method.
UNIT:3
Q1. What is the purpose of a controller in Laravel?
a) To handle database operations.
b) To render views in the browser.
c) To define routes and handle HTTP requests.
d) To manage authentication and authorization.
Answer: c) To define routes and handle HTTP requests.
Q2. How do you create a new controller in Laravel using the artisan command-line tool?
a) php artisan create:controller MyController
b) php artisan make:controller MyController
c) php artisan generate:controller MyController
d) php artisan controller:create MyController
Answer: b) php artisan make:controller MyController
Q3. Which method is commonly used to return a view from a controller in Laravel?
a) render()
b) make()
c) view()
d) load()
Answer: c) view()
Q4. What is Blade in Laravel?
a) A templating engine for generating HTML.
b) A database migration tool.
c) A command-line interface for artisan commands.
d) A middleware for handling HTTP requests.
Answer: a) A templating engine for generating HTML.
Q5. How do you pass data from a controller to a Blade view in Laravel?
a) By using the requestData() method.
b) By using the view()->with() method.
c) By passing data as an array in the view() function.
d) By using the Blade::share() method.
Answer: b) By using the view()->with() method.
Q6. Which symbol is used to comment in Blade templates?
a) //
b) /* */
c) #
d) {{-- --}}
Answer: d) {{-- --}}
Q7. How can you include a Blade template within another Blade template in Laravel?
a) By using the @include() directive.
b) By using the @extends() directive.
c) By using the @yield() directive.
d) By using the @section() directive.
Answer: a) By using the @include() directive.
Q8. What is the purpose of route model binding in Laravel?
a) To automatically generate routes based on models.
b) To bind a specific model instance to a route parameter.
c) To authenticate users based on their models.
d) To validate route parameters using model rules.
Answer: b) To bind a specific model instance to a route parameter.
Q9. How can you define a route with multiple HTTP methods in Laravel?
a) By using the Route::all() method.
b) By defining separate routes for each HTTP method.
c) By using the Route::match() method.
d) By using the Route::any() method.
Answer: c) By using the Route::match() method.
Q10. How can you create a route group with a prefix in Laravel?
a) By using the Route::group() method.
b) By using the Route::prefix() method.
c) By using the Route::setPrefix() method.
d) By using the Route::withPrefix() method.
Answer: b) By using the Route::prefix() method.
Q11. Which method is used to define a fallback route in Laravel?
a) Route::fallback()
b) Route::notFound()
c) Route::catch()
d) Route::default()
Answer: a) Route::fallback()
Q1. How can you prefix routes in Laravel?
a) By using the Route::prefix() method.
b) By using the Route::group() method.
c) By using the Route::name() method.
d) By using the Route::middleware() method.
Answer: a) By using the Route::prefix() method.
Q2. What is domain routing in Laravel?
a) Routing based on the request's HTTP method.
b) Routing based on the request's domain name.
c) Routing based on the request's query parameters.
d) Routing based on the request's IP address.
Answer: b) Routing based on the request's domain name.
Q3. What is the purpose of middleware in Laravel?
a) To define routes and handle HTTP requests.
b) To generate HTML templates.
c) To handle authentication and authorization.
d) To manage database operations.
Answer: c) To handle authentication and authorization.
Q4. Which command is used to create a new resource controller in Laravel?
a) php artisan make:controller ResourceController--resource
b) php artisan generate:controller ResourceController-- restful
c) php artisan controller:create ResourceController-- resource
d) php artisan make:controller ResourceController--restful
Answer: a) php artisan make:controller ResourceController--resource
Q5. In Blade, how do you create a new template file?
a) By using the create() method in the Blade class.
b) By using the generate:template artisan command.
c) By manually creating a new file with the .blade.php extension.
d) By using the template() helper function.
Answer: c) By manually creating a new file with the .blade.php extension.
Q6. How do you output a variable value in Blade templates?
a) By using the echo statement.
b) By using the print statement.
c) By using the {{ $variable }} syntax.
d) By using the @output($variable) directive.
Answer: c) By using the {{ $variable }} syntax.
Q7. Which directory is commonly used to store controllers in Laravel?
a) app/Controllers
b) app/Http/Controllers
c) controllers/
d) resources/controllers/
Answer: b) app/Http/Controllers
Q8. How can you extend a Blade template from another template?
a) By using the @extends() directive.
b) By using the @include() directive.
c) By using the @yield() directive.
d) By using the @extend() directive.
Answer: a) By using the @extends() directive.
Q9. What is the purpose of named routes in Laravel?
a) To assign a unique name to each route.
b) To group related routes together.
c) To secure routes with authentication.
d) To define route parameters and constraints.
Answer: a) To assign a unique name to each route.
Q10. How do you create a secure route that requires authentication in Laravel?
a) By using the Route::secure() method.
b) By using the Route::auth() method.
c) By adding the auth middleware to the route.
d) By using the Route::authenticated() method.
Answer: c) By adding the auth middleware to the route.
Q11. How can you define parameter constraints in Laravel routes?
a) By using regular expressions in the route definition.
b) By using the Route::constraint() method.
c) By using the Route::where() method.
d) By using the Route::parameters() method.
Answer: c) By using the Route::where() method.
Q12. How can you group routes in Laravel?
a) By using the Route::group() method.
b) By using the Route::prefix() method.
c) By using the Route::middleware() method.
d) By using the Route::namespace() method.
Answer: a) By using the Route::group() method.