Laravel Interview Question Answer
1 - What is default packages of Laravel 5.4 ?

Cashier
Envoy
Passport
Scout
Socialite

2 - What is use of intended?

return redirect()->intended('dashboard');
The intended method on the redirector will redirect the user to the URL they were attempting to access before being caught by the authentication filter.

3 - What is Laravel service container?

One of the most powerful feature of Laravel is its Service Container. It is a powerful tool for resolving class dependencies and performing dependency injection in Laravel.

instead of creating objects manually with the new keyword, you can register a binding on the Service Container,and create an instance through the service container.

4 - What is composer?

Composer is a tool for manage dependency in php. Dependency means suppose you want to install Laravel Framework and Laravel require other packages. so if Install laravel by Composer then laravel install and other required packages is also install.

5 - What is dd() function in laravel ?

dd() is a helper function. It stands for Dump and Die which is used to dump a variable(print variable data) and stop execution.

for example
dd($array);

6 - How to debug laravel query?

// Enable query log(Write top of the function)
DB::enableQueryLog();

// To print Laravel mysql query with parameters
dd(DB::getQueryLog());

7 - Difference between firstOrCreate/ firstOrNew

The firstOrCreate method will attempt to locate a database record using the given column / value pairs. If the model can not be found in the database, a record will be inserted with the attributes from the first parameter, along with those in the optional second parameter.

The firstOrNew method, like firstOrCreate will attempt to locate a record in the database matching the given attributes. However, if a model is not found, a new model instance will be returned. Note that the model returned by firstOrNew has not yet been persisted to the database. You will need to call save manually to persist it:

8 - What is PHP Artisan commands?

PHP artisan is run on command line interface, By php artisan we can create controller, modal, project down/up, database migration etc. for this we just goto your project

c:\xampp\htdocs\shishirtest>

Then enter artisan command, some example of artisan.

To create controller
php artisan make:controller controllername

To enable maintenance mode
php artisan down

To disable maintenance mode
php artisan up

To see list of artisan command
php artisan list

9 - How can we know which Laravel version we are using in project?

1- php artisan --version
2- composer.json that is located in root

10 - What is Dependency Injection

Dependency injection is a fancy phrase that essentially means class dependencies are “injected” into the class via the constructor or, in some cases, "setter" methods.

PHP Code

namespace App\Http\Controllers;

use App\User;
use App\Repositories\UserRepository;
use App\Http\Controllers\Controller;

class UserController extends Controller
{
public function __construct(UserRepository $users)
{
$this->users = $users;
}
}

In the above example, A class UserRepository is injected by constructor, that retrieve user information from the database.

Note: Class UserRepository is injected by constructor is call Dependency Injection

11 - Difference between Match and Any

Match is use for multiple HTTP verbs.
Route::match(['get', 'post'], '/', function () {
//
});

Any is use for all HTTP verbs.
Route::any('/', function () {
//
});

12 - Difference between Redirect Intended and Redirect To

Redirect Intended : redirects the user to where they were originally going

Redirect To : Redirect the user to the page you specify them to go.

13 - What is PSR-4 in Laravel?

By PSR-4 , We can define namesaces in any location, For example we create user namespace that looks classes for
app/usersection and we define location in composer.json.

 

"autoload": {
"classmap": [
"app/database/migrations",
"app/database/seeds"
],

"psr-4": {
"User\\": "app/usersection/",

}
},

14 - About Laravel 6.0

Laravel 6.0 Released on 3rd Sep 2019 with LTS Version.

Sept 3rd, 2021 Bug Fixes Until

Sept 3rd, 2022 Security Fixes Until

15 - In Laravel How can we extend login expire time in Login Auth

Goto config->auth.php
See the below code in bottom and change expire time
'passwords' => [
'users' => [
'provider' => 'users',
'table' => 'password_resets',
'expire' => 60,
],
],

16 - How many type Laravel Router Methods?

Route::get($uri, $callback);
Route::post($uri, $callback);
Route::put($uri, $callback);
Route::patch($uri, $callback);
Route::delete($uri, $callback);
Route::options($uri, $callback);

17 - What is contracts?

Contracts are set of interfaces that define the core services provided by the framework.For example for email services we use contractIlluminate\Contracts\Mail\Mailer 

18 - What is LTS Version of Laravel?

LTS stands for Long Term Support. It means

bugfixes for that version will be provided until

the next LTS version. For Non LTS Version bugfixes
provided only 6 month.

Laravel LTS Version
Laravel 5.1
Laravel 5.5

19 - What are service providers?

All laravel application is bootstrapped in Service providers. Our application and all laravel services are also bootstrapped by service providers.

Service providers connect your package into laravel.A service provider is responsible for binding things into Laravel's service container and informing Laravel.

Mostly service providers contain register and boot method, All service providers extend the IlluminateSupportServiceProvider class.

20 - Laravel features

Inbuilt CRSF(cross-site request forgery)
Inbuilt paginations
Reverse Routing
Query builder
Database migration
Authentication
Template engine

21 - What are the server requirements for Laravel 5.5?

PHP >= 7.0.0
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension

22 - Below are types of relationships supported by Laravel Eloquent ORM.

One To One
One To Many
One To Many (Inverse)
Many To Many
Has Many Through
Polymorphic Relations
Many To Many Polymorphic Relations

23 - What are the server requirements for Laravel 5.8?

PHP >= 7.1.3
OpenSSL PHP Extension
PDO PHP Extension
Mbstring PHP Extension
Tokenizer PHP Extension
XML PHP Extension
Ctype PHP Extension
JSON PHP Extension
BCMath PHP Extension

24 - Explain Auth::routes();

Auth::routes() is just a helper class that helps you generate all the routes required for user authentication.

// Authentication Routes...
$this->get('login', 'Auth\LoginController@showLoginForm')->name('login');
$this->post('login', 'Auth\LoginController@login');
$this->post('logout', 'Auth\LoginController@logout')->name('logout');

// Registration Routes...
$this->get('register', 'Auth\RegisterController@showRegistrationForm')->name('register');
$this->post('register', 'Auth\RegisterController@register');

// Password Reset Routes...
$this->get('password/reset', 'Auth\ForgotPasswordController@showLinkRequestForm');
$this->post('password/email', 'Auth\ForgotPasswordController@sendResetLinkEmail');
$this->get('password/reset/{token}', 'Auth\ResetPasswordController@showResetForm');
$this->post('password/reset', 'Auth\ResetPasswordController@reset');

25 - Difference between first() or get()

In Laravel, We use first and get to fetch data from database

$users=DB::table('users')->where('city','Delhi')->first();
$users->name;

Return array of object


$users=DB::table('users')->where('city','Delhi')->get();
$users[0]->name;

Return single object


Next

Share on Facebook
Success Story
Saurabh Khurana
Avatar
PHP Developer
Marstech Conslutant
There is a great demand of PHP these days. After completing my graduation, I thought to join a SEO course. However, I am not aware of any institutions, where I can undertake this training. My friend suggested to join IT Training Online, and believe me I have been benefited to a great extent.
Amulya Prakash Bajpai
Avatar
PHP Programmer
Webdesigning2u
My friends were all working in big companies and I was trying to put my foot on to something to just survive. I started taking PHP training from It and Dc and then after completion I was placed by them in a good company. I am now earning in good way. My friends appreciate my efforts too.
Sponsored Ads