100 Top Interview Laravel Question for Fresher and Experience

 

100 Laravel Framework Interview Question


1) Describe Laravel?

 Laravel is MVC(Model View Controller) architecture based open Source php Framework developed by Taylor Otwell. Latest version of Laravel Framework is 7.0 which got released on March 3rd.

Laravel 1st version got released on 9th June 2011.



2) What are the Laravel Framework Feature ?

 Top Feature of laravel Framework is below.

  • CRSF (cross-site request forgery )
  • Eloquent ORM
  • Laravel paginations
  • Database Seeding
  • Reverse Routing
  • Query builder
  • Route caching
  • Database Migration
  • Unit Testing
  • IOC (Inverse of Control) Container.
  • Job middleware
  • Lazy collections



3) Define Laravel Eloquent ORM ?

Laravel Eloquent feature is object Oriented paradigm approach of database communication. In Eloquent we create Model for each Table in the database, which set the communication (Fetching, Inserting, Deleting, Modifying the Record ) with database. It represent Database Table as a Class.



Laravel Eloquent ORM With Example Read More






4) What is Soft Delete? How to use it in Laravel Model?

Soft Delete is feature of laravel framework which helps when model is soft deleted. In this scenario the data record is not deleted form the database table instead deleted_at timestamp is maintained.




5) Define Laravel Query Builder ?

Query Builder in Larevel is a Package through which we create and run database query Quickly to run the application smoothly. Query Bulider Use PHP Data Object (PDO) where we dont have to worry about the SQL Injection. It can perform all Database Operation such as CRUD, DB Connection, Aggregate Function etc.



Laravel Query Builder With Example Read More






6) Explain Middleware Concept in Laravel?

Laravel Middleware provide a filter as well as it act as interface or Middle-Man between HTTP request and response which access the application. Middleware is a way to filter all the bad or Forgery request which try to access your Application.

Laravel Middleware Type 
  • Global Middleware 
  • Route Middleware


Laravel Middleware With Example Read More






7) Define Aggregate Function ? What are the aggregate function available in Lravel Query Builder?

In Aggregate Function, Database Table Rows are grouped together based on certain Criteria to get specific summary value. Laravel Provide various aggregate function which we can use in our query, list is below for your reference.
  • count() function
  • max() function
  • min() function
  • sum() function
  • avg() function
Note: All Aggregate function defined above ignore NULL Value except Count() function.



8) Explain Laravel Migration? Write the Artisan Command for Laravel Migration ?

Laravel Database Migration is way through which we build and maintain the Database Schema. Migration is Version Control of Your DB, which will allow Developer team easily to modify and share the DB Schema.

Laravel DB Migration provide the facility for those who is not able and poor in maintaining, updating Database.

Migration In Laravel contain by default Two method up() method is called when a DB is modified or changed. Whereas, the DB Migration down() method is called when DB is reverted back.


Artisan Command for Laravel migration.    php artisan migrate



9) Describe Laravel Reverse Routing ?

Laravel reverse Routing is one of the Awesome Route Feature. Reverse Routing is process of generating the URL based on the Route Deceleration. Reverse Routing sets a relationship between links and web routes.

Consider below route declared as Example (consider your Website as www.abc.com)

Route::get('user-login','UserController@userLogin');

{ { url( '/usre-login' ) } }

$url-link = URL::route('usre-login');

$redirect
-link = Redirect::route('usre-login');

Above three will generate the URL which is below as a example :

URL : www.abc.com/user-login

Now reverse routing is process to generate the url based on Name or other parameter.

  {{ HTML :: link_to_action( ' UserController@userLogin ' ) }}  

This above reverse routing will also generate or point the same URL www.abc.com/user-login .

 
10) What is Artisan ? List some Common Php Artisan command?

 Artisan is command line Interface tool which help in laravel Application Building. To Kmow all this List of Artisan command, Use the below Artisan command.

php artisan list

 List of Common Artisan Command for hassle free Laravel application Development is below:-
  • php artisan list
  • php artisan make:controller controller-name
  • php artisan make:model model-name  
  • php artisan migrate
  • php artisan make:middleware middleware-name  
  • php artisan tinker


11) Define Controller ?

Controller handle all the HTTP Request logically and divert the Web Traffic to View and Model. It Contain all the Http Handling Logic within Single Class. Artisan Command to create the Controller is below for your Reference.

php artisan make:controller controllerName

Controller is C of  MVC(Model View Controller).


12) List out some Laravel Official Packages?

Laravel Packages list is below for your reference.
  • Dusk Package
  • Envoy Package
  • Horizon Package
  • Cashier Package
  • Passport Package
  • Scout Package
  • Socialite Package
  • Telescope Package
 

13) What is the difference between find() and where() method in laravel?

The Major Difference between them is find() method always use Primary Key to filter the table record, whereas where() method uses any table column to filter the table record set.

find() method will return the single table row from the database. where() method return multiple record based on the condition.



14) What is Named Route in Laravel ?

Named Route is a friendly name given to the route the reference. We can use Named rout to specify the particular Route as well as to generate the URL / to redirect to specific URL.

Route::post('profile-data/save', 'ProfileController@saveProfile')->name('profileData');

You must keep the route name always unique. Generating / Redirecting Url for Names Route is below for your reference.

$url = route('profile');
return redirect()->route('profile');

With Name Route we can pass the second or third parameter as a argument.

Route::post('profile-data/{id}', 'ProfileController@updateProfile')->name('profileData');

To pass the parameter as argument in the named Route code is below for your reference.

$url = route('profile', ['id'=>1 ]);

If we pass the additional parameter in the array, that will be automatically added in the URL generated query String. Below is the example for reference.

$url = route('profile-data/{id}', ['id' => 1, 'rollno' => '1004']);
URL String generated is below /1/profile?rollno=1004



15) Define Laravel Validation?

Laravel Validation is the way through which we can verify and filter the data coming to the Application database. We can have clean and validated data in the database coming with HTTP with powerful validation rule.

As we know that we store the data in the Database using form. As we must not fill our database with junk and invalid data, we do form validation in client Side as well as server side. The validation purpose is to get the exact data what is required for application.

You can use validate method for data filteration.

$validatedData = $request->validate([
            'FULL_NAME' => 'required|max:25',
            'mobile' => 'required|digits:10|unique:valid_table,mobile',
            'email' => 'required|email|max:255',
        ]);

You can use Validation make() method to create manual validator.

$validator = Validator::make($request->all(), [
            'first_name' => 'required|max:255',
            'mobile' => 'required|digits:10',
        ])->validate();



16) Define Route::fallback method with Example?

Route::fallback method is another feature of  Laravel Routing in which we handle the HTTP request which do not match with our route list. By default laravel render the 404 not found page using exception handler. Now laravel fallback method you can define and redirect to the view which will get execute if not HTTP request matches.

You must always define the Route::fallback method at the last of route file. Below is the code for your reference.

Route::fallback(function() {
    return 'You have landed on wrong url. ';
});




Global and Route middleware in Laravel

Laravel Middleware concept from Scratch 

Global and Route Middleware in Laravel

Laravel Middleware provide a filter as well as it act as interface or Middle-Man between HTTP request and response which access the application. Middleware is a way to filter all the bad or Forgery request which try to access your Application.

Laravel Middleware Type 
  • Global Middleware 
  • Route Middleware

Before using any middleware you have to register in Kernal.php. Go to App\Http laravel project Directory, There Kernel.php file is there which have all the Global, Route middleware configure by default for you. If you want to use your custom Middleware you must register that in any one below category.

Global Middleware act on each HTTP Request which try to access the application. By default, Some Middleware is declared as Global in Kernal.php file. See the code below,
 
 /**      * The application's global HTTP middleware stack.      *      * These middleware are run during every request to your application.      *      * @var array      */ protected $middleware = [
 \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,  \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,  \App\Http\Middleware\TrimStrings::class,  \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,  \App\Http\Middleware\TrustProxies::class,
];
 

Route Middleware will act on specified HTTP Request which access the Application.

/**      * The application's route middleware.      *      * These middleware may be assigned to groups or used individually.      *      * @var array      */ protected $routeMiddleware = [ 
 'auth' => \Illuminate\Auth\Middleware\Authenticate::class,  'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,  'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,  'can' => \Illuminate\Auth\Middleware\Authorize::class,  'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,  'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,   
];
 
Route Group Middleware is another categories where sometime you need to apply the middleware on group of route. At that time you must have to register your Middleware in Kernal.php. See the below code of Kernal.php

/**      * The application's route middleware groups.      *      * @var array      */ protected $middlewareGroups = [ 
  'web' => [   \App\Http\Middleware\EncryptCookies::class,   \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,   \Illuminate\Session\Middleware\StartSession::class,   \Illuminate\View\Middleware\ShareErrorsFromSession::class,   \App\Http\Middleware\VerifyCsrfToken::class,   \Illuminate\Routing\Middleware\SubstituteBindings::class,         ],         'api' => [             'throttle:60,1',             'bindings',         ],     ];
  
 

How to Create Middleware in Laravel


You can create your own custom Middleware for your usage. Below is Artisan Command for creating middleware.

php artisan make:middleware MiddlewareName

Lets Create one Custom Middleware named with  MyCustomMiddleware

php artisan make:middleware MyCustomMiddleware

Below is the code sample by default in MyCustomMiddleware

  class MyCustomMiddleware {     /**      * Handle an incoming request.      *      * @param  \Illuminate\Http\Request  $request      * @param  \Closure  $next      * @return mixed      */     public function handle($requestClosure $next)     {         return $next($request);     } }  

Once the custom Middleware is created we must register in the Kernnal.php in App\Http\ Project directory.

Register Custom-Middleware as Global

Register MyCustomMiddleware  as a Global Middleware in kernal.php file and you can use that on route. Below code is the Example to register as global.


 
 /**      * The application's global HTTP middleware stack.      *      * These middleware are run during every request to your application.      *      * @var array      */ protected $middleware = [
 \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class,  \Illuminate\Foundation\Http\Middleware\ValidatePostSize::class,  \App\Http\Middleware\TrimStrings::class,  \Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::class,  \App\Http\Middleware\TrustProxies::class,
 \App\Http\Middleware\MyCustomMiddleware::class,
];
 

In the above Global Middleware we have declare our MyCustomMiddleware, Now each HTTP request which will try to access the Application, will be passed and verified through this middleware. When we register our Middleware ware as a global in Kernal.php, Each HTTP Request will be filtered with this Global Middleware.

Register Custom-Middleware as Route Specific

Register MyCustomMiddleware in Kernal.php as a route specific middleware.

/**      * The application's route Specific middleware.      *      * These middleware may be assigned to groups or used individually.      *      * @var array      */ protected $routeMiddleware = [ 
 'auth' => \Illuminate\Auth\Middleware\Authenticate::class,  'auth.basic' => \Illuminate\Auth\Middleware\AuthenticateWithBasicAuth::class,  'bindings' => \Illuminate\Routing\Middleware\SubstituteBindings::class,  'can' => \Illuminate\Auth\Middleware\Authorize::class,  'guest' => \App\Http\Middleware\RedirectIfAuthenticated::class,  'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
 'myCustom' => \App\Http\Middleware\MyCustomMiddleware::class, 
];

Route specific Middleware will be applied on Specific route. So each HTTP request made on the specific route will be filtered and access to the application.

Register Custom-Middleware as Route Group Specific

Register Group Specific Route middleware in kernal.php. This we can apply on group of  route like admin section Route or etc. 

/**      * The application's route middleware groups.      *      * @var array      */ protected $middlewareGroups = [ 
  'web' => [   \App\Http\Middleware\EncryptCookies::class,   \Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::class,   \Illuminate\Session\Middleware\StartSession::class,   \Illuminate\View\Middleware\ShareErrorsFromSession::class,   \App\Http\Middleware\VerifyCsrfToken::class,   \Illuminate\Routing\Middleware\SubstituteBindings::class,
\App\Http\Middleware\MyCustomMiddleware::class,
         ],         'api' => [             'throttle:60,1',             'bindings',         ],     ];

Apply Middleware on Laravel Route file

In Laravel middleware act on the HTTP Request, and the HTTP Request is made through route. So after registering the Middleware in Kernel.php, now we will see how to apply the custom-middleware on route.
/* Below Example is the Example of Route Specific Middleware Declaration */  
Route::get('/'function () {     return view('welcome'); })->middleware('myCustom');

 /* Group Route Specific Middleware Example  */ Route::group(['prefix' => 'admin' , 'middleware' =>['web']], function () { Route::get('user-login','UserController@userLogin'); Route::post('user-verify','UserController@userVerify');
 });

Uttarakhand Objective gk Question in English

Uttarakhand Objective GK Question






  1. The devastating flood which is known as Himalayan Tsunami was occured in the year
    1. A. 2010     
    2. B. 2012      
    3. C. 2013        Correct Answer
    4. D. 2014      
  2.  

    Which city is also known as the "Yoga Capital of the World"
    1. A. Dehradun     
    2. B. Nainital      
    3. C. Haridwar      
    4. D. Rishikesh        Correct Answer
  3.  

    Total number of National Parks in Uttarakhand
    1. A. 5     
    2. B. 7        Correct Answer
    3. C. 8      
    4. D. 10      
  4.  

    What is the literacy rate of Uttarakhand according to 2011 census
    1. A. 73.81 %     
    2. B. 75.32 %      
    3. C. 79.63 %        Correct Answer
    4. D. 79.90 %      
  5.  

    Besides Hindi, which one is the other official language of Uttarakhand
    1. A. English     
    2. B. Sanskrit        Correct Answer
    3. C. Nepali      
    4. D. Urdu      
  6.  

    Total number of districts in Uttarakhand
    1. A. 10     
    2. B. 12      
    3. C. 13        Correct Answer
    4. D. 15      
  7.  

    Who was the first Chief Minsiter of Uttarakhand
    1. A. B. S. Koshyari     
    2. B. N. D. Tiwari      
    3. C. Nityanand Swami        Correct Answer
    4. D. B. C. Khanduri      
  8.  

    Which one is the highest mountain in Uttarakhand
    1. A. Nanda Devi       Correct Answer
    2. B. K2      
    3. C. Kangchenjunga      
    4. D. Chimborazo      
  9.  

    Which river passed through the Valley of Flowers
    1. A. Alaknanda River     
    2. B. Bhagirathi River      
    3. C. Ramganga      
    4. D. River Pushpawati        Correct Answer
  10.  

    In which district, the Jageshwar temple is located
    1. A. Dehradun     
    2. B. Chamoli      
    3. C. Haridwar      
    4. D. Almora        Correct Answer
  11.  

    The Char Dham Yatra begins every year in the month of
    1. A. April     
    2. B. May        Correct Answer
    3. C. September      
    4. D. December      
  12.  

    In which year Uttarakhand was established as a separate state
    1. A. 1998     
    2. B. 2000        Correct Answer
    3. C. 2001      
    4. D. 2003      
  13.  

    Which one is the largest district by area wise in Uttarakhand
    1. A. Uttarkashi       Correct Answer
    2. B. Pithoragarh      
    3. C. Pauri Garhwal      
    4. D. Nainital      
  14.  

    At Dev Prayag, the Bhagirathi river meets with the
    1. A. Nandakini River     
    2. B. Mandakini River      
    3. C. Alaknanda River        Correct Answer
    4. D. Ganga River      
  15.  

    In which year, the Chipko Movement was awarded with the Right Livelihood Award
    1. A. 1987       Correct Answer
    2. B. 1990      
    3. C. 1994      
    4. D. 1998      
  16.  

    The Treaty of Sugauli took place in the year
    1. A. 1801     
    2. B. 1805      
    3. C. 1811      
    4. D. 1815        Correct Answer
  17.  

    According to 2011 census, which district of Uttarakhand had negative population growth rate
    1. A. Pithoragarh     
    2. B. Almora        Correct Answer
    3. C. Rudraprayag      
    4. D. Uttarkashi      
  18.  

    Which one is the largest glacier in Uttarakhand
    1. A. Bandarpunch Glacier     
    2. B. Dokriani Glacier      
    3. C. Gangotri Glacier        Correct Answer
    4. D. Pindari Glacier      
  19.  

    The Uttarakhand High Court is located at
    1. A. Nainital       Correct Answer
    2. B. Haldwani      
    3. C. Dehradun      
    4. D. Rishikesh      
  20.  

    Which lake of Uttarakhand is also known as "mystery lake"
    1. A. Nainital     
    2. B. Sattal      
    3. C. Roopkund        Correct Answer
    4. D. Naukuchiatal      
  21.  

    'Pinder River' joins Alaknanda at
    1. A. Vishnu Prayag     
    2. B. Joshi Math      
    3. C. Rudra Prayag      
    4. D. Karna Prayag        Correct Answer
  22.  

    Which one of the following is a biosphere reserve in Uttarakhand
    1. A. Gobind     
    2. B. Corbett      
    3. C. Rajaji      
    4. D. Nanda Devi        Correct Answer
  23.  

    Which Queen is also known as "Nakati Rani" in Garhwal
    1. A. Guleria Rani     
    2. B. Karnavati Rani        Correct Answer
    3. C. Nepalia Rani      
    4. D. kamlendumati Rani

Our Feature Post

There is a tree between houses of A and B If the tree leans on As House

    There is a tree between houses of A and B. If the tree There is a tree between houses of A and B. If the tree leans on A’s House, the t...

Our Popular Post