Frequently Asked PHP Laravel Interview Questions

I think Laravel is the best PHP framework. Here i am sharing some frequently asked laravel interview questions. There are many features which makes Laravel best PHP framework like Routing, Artisan, Eloquent, Blade templates, Migrations, Easy authentication.

Frequently Asked Laravel Interview Questions:

1. How many types of databases support laravel?

Laravel supports 4 types of databases:

  • MySQL
  • Postgres
  • SQLite
  • SQL Server

2. What is dd() function in laravel?

dd() means dump and die. In laravel, we use this function to dump variable like PHP var_dump() function. It will halt the execution of script after dumping variable.

3.Types of Eloquent relationships in Laravel

There are many types of relationships in laravel:

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

4. What are the defaul packages provided by Laravel?

These are the default packages provided by Laravel:

  • Cashier
  • Dusk
  • Envoy
  • Horizon
  • Passport
  • Scout
  • Socialite
  • Telescope

5. What are the Server Requirements for Laravel?

These are the server requirements of Laravel:

  • 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

6. How to install Laravel Using Composer?

Run the below command in your terminal to install Laravel in “laravel-demo” directory:

composer create-project --prefer-dist laravel/laravel laravel-demo

7. What is Composer?

Composer is an application-level package manager for the PHP programming language
that provides a standard format for managing dependencies of PHP software and required libraries.
It was developed by Nils Adermann and Jordi Boggiano, who continue to manage the project.

8. How to set application key in Laravel?

Run the below command in your terminal:

php artisan key:generate

9.What is the current version of Laravel?

The current version of Laravel is “5.7”.

10. Laravel database configuration

When you install laravel, manually then you can find .env.example file in your laravel installation root folder. Then you need to rename it to .env.

But when you will install laravel using composer then you can find .env file in your laravel installation folder.

You can configure your database by editing .env file, the default configuration is for MYSQL.

When you edit .env file you need to change below info:

How to compare date in Laravel?

There are many ways to display date and format like using PHP date function. But i think it will be better to use included package.

By default laravel comes withe Carbon package. It is a simple PHP API extension for DateTime.

You need to add Carbon\Carbon namespace where you want to use it like below:

Here i am going to show you laravel eloquent Date comparision whereDate / whereMonth / whereDay / whereYear.

a. Fetch all records from users table where the date is equal to the current date.

b.Fetch all records from users table where the month is equal to a current month.

c.Fetch all records from users table where a day is equal to the particular day of a month.

d.Fetch all records from users table where the year is equal to the current year.

Gaurav Kumar

Hi, my name is Gaurav Kumar and I specialize in the Computer Software industry. I have been working as a Software Developer, and it's my passion to learn new things and sharing what I've learned.