Here, i created a Laravel interview question and answer list, which are asked to me during the Laravel interview.
1. What is Laravel?
Laravel is an open-source widely used PHP framework. The platform was intended for the development of web application by using MVC architectural pattern.
2. What is the latest Laravel version?
The latest Laravel version is version 8, which was released on 8th September 2020. And we are waiting for Laravel 9, which is coming in this year that is 2022.
3. What is composer?
It is an application-level package manager for PHP. It provides a standard format for managing PHP software dependencies and libraries.
4. Name aggregates methods of query builder.
Aggregates methods of query builder are: 1) max(), 2) min(), 3) sum(), 4) avg(), and 5) count().
5. What is HTTP middleware?
HTTP middleware is a technique for filtering HTTP requests. Laravel includes a middleware that checks whether application user is authenticated or not.
6. What is a Route in Laravel?
In Laravel, all requests are mapped with the help of routes. Basic routing routes the request to the associated controllers. This chapter discusses routing in Laravel. Routing in Laravel includes the following categories −
- Basic Routing
- Route parameters
- Named Routes
7. Explain reverse routing in Laravel.
Reverse routing is a method of generating URL based on symbol or name. It makes your Laravel application flexible.
8. How will you register service providers?
We can register service providers in the config/app.php configuration file that contains an array where you can mention the service provider class name.
9. What is Laravel’s Facades?
A Laravel facade is a class which provides a static-like interface to services inside the container. These facades, according to the documentation, serve as a proxy for accessing the underlying implementation of the container’s services.
All facades of Laravel have defined in Illuminate\Support\Facades namespace.
10. How can you enable query log in Laravel?
We can use enableQueryLog method to enable query log in Laravel.
11. Explain the concept of events in Laravel.
An event is an occurrence or action that help you to subscribe and listen for events that occur in Laravel application. Some of the events are fired automatically by Laravel when any activity occurs.
12. What are validation concept in Laravel?
It ensures that the data is always in an expected format before it stores into the database. Laravel provides many ways to validate your data.
Base controller trait uses a ValidatesRequests class which provides a useful method to validate requests coming from the client machine.
13. List available types of relationships in Laravel Eloquent.
Types of relationship in Laravel Eloquent are: 1) One To One 2) One To Many 3) Many To Many 4) Has Many Through, and 5) Polymorphic Relations.
14. Why are migrations important?
Migrations are important because it allows you to share application by maintaining database consistency. Without migration, it is difficult to share any Laravel application. It also allows you to sync database.
15. What is the use of dd() function?
This function is used to dump contents of a variable to the browser. The full form of dd is Dump and Die.
16.List out common artisan commands used in Laravel.
Laravel supports following artisan commands:
- PHP artisan down;
- PHP artisan up;
- PHP artisan make:controller;
- PHP artisan make:model;
- PHP artisan make:migration;
- PHP artisan make:middleware;
17. Explain faker in Laravel.
It is a type of module or packages which are used to create fake data. This data can be used for testing purpose.
It is can also be used to generate: 1) Numbers, 2) Addresses, 3) DateTime, 4) Payments, and 5) Lorem text.
18. How will you check table is exists or in the database?
Use hasTable() Laravel function to check the desired table is exists in the database or not.
19. What is the significant difference between insert() and insertGetId() function in Laravel?
- Insert(): This function is simply used to insert a record into the database. It not necessary that ID should be auto incremented.
- InsertGetId(): This function also inserts a record into the table, but it is used when the ID field is auto-increment.
20. Explain active record concept in Laravel.
In active record, class map to your database table. It helps you to deal with CRUD operation.
21. What is Laravel guard?
Laravel guard is a special component that is used to find authenticated users. The incoming requested is initially routed through this guard to validate credentials entered by users. Guards are defined in ../config/auth.php file.
22. What are policies classes?
Policies classes include authorization logic of Laravel application. These classes are used for a particular model or resource.
23. How to rollback last migration?
Use need to use artisan command to rollback the last migration.
php artisan migrate:rollback –step=1
24. What do you mean by Laravel Dusk?
Laravel Dusk is a tool which is used for testing JavaScript enabled applications. It provides powerful, browser automation, and testing API.
25. Explain API.PHP route.
Its routes correspond to an API cluster. It has API middleware which is enabled by default in Laravel. These routes do not have any state and cross-request memory or have no sessions.
26. What is named route?
Name route is a method generating routing path. The chaining of these routes can be selected by applying the name method onto the description of route.
Route::get( ‘/user/profile’, [UserProfileController::class, ‘show’] )->name(‘profile’);
27. Define hashing in Laravel.
It is the method of converting text into a key that shows the original text. Laravel uses the Hash facade to store the password securely in a hashed manner.