Laravel advanced interview questions and answers

Advanced interview questions and answers on Laravel Framework

1.Define Active Record Implementation. How to use it Laravel ?

Active Record Implementation is an architectural pattern found in software engineering that stores in-memory object data in relational databases. Active Record facilitates the creation and use of business objects whose data is required to persistent in database. Laravel implements Active Records by Eloquent ORM. Below is sample usage of Active Records Implementation is Laravel.

$product = new Product;
$product->title = 'Iphone 6s';

Active Record style ORMs map an object to a database row. In the above example, we would be mapping the Product object to a row in the products table of database.

2.List Types of relationships supported by Laravel.

Laravel support 7 types of table relationships, they are

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

3. What is Query Builder ?

Laravel’s database query builder provides a suitable, easy interface to creating and organization database queries. It can be used to achieve most database operations in our application and works on all supported database systems. The Laravel query planner uses PDO restriction necessary to keep our application against SQL injection attacks

4. What is Laravel Elixir ?

Laravel Elixir provides a clean, fluent API for defining basic Gulp tasks for your Laravel application. Elixir supports common CSS and JavaScript preprocessors like Sass and Webpack. Using method chaining, Elixir allows you to fluently define your asset pipeline (source:

5. How to enable maintenance mode in Laravel 5 ?

You can enable maintenance mode in Laravel 5,simply by executing below command.

To enable maintenance mode
php artisan down
To disable maintenance mode
php artisan up

6.List out Databases Laravel supports ?

Currently Laravel supports four major databases, they are :-

  • MySQL
  • Postgres
  • SQLite
  • SQL Server

7.How to get current environment in Laravel 5 ?

You may access the current application environment via the environment method.

		$environment = App::environment();

8. What is the purpose of using dd() function iin laravel ?

Laravel’s dd() is a helper function ,which will dump a variable’s contents to the browser and halt further script execution.

9. What is Method Spoofing in Laravel ?

As HTML forms does not supports PUT, PATCH or DELETE request. So, when defining PUT, PATCH or DELETE routes that are called from an HTML form, you will need to add a hidden _method field to the form. The value sent with the _method field will be used as the HTTP request method:

<form action="/foo/bar" method="POST">
    <input type="hidden" name="_method" value="PUT">
    <input type="hidden" name="_token" value="{{ csrf_token() }}">

To generate the hidden input field _method, you may also use the method_field helper function:

&lt?php echo method_field('PUT'); ?>

In Blade template you can write it as below

{{ method_field('PUT') }}

10. What are Model Factories ?

11. What are Accessors and Mutators in Eloquent and why should you use them?

12. How do you register a middleware?

13. How to setup localization for an application in Laravel?

14. Explain terminable Middleware?

15. What is an Observer?

Here you can find complete guide to configure databases in Laravel

Leave a Reply

Your email address will not be published. Required fields are marked *