Skip to content

deantawonezvi/Top-Laravel-Interview-Questions-Wiki

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 

Repository files navigation

Top Laravel Interview Questions & Answers

Click ⭐ if you like the project. Pull Request are highly appreciated.

Table of Contents

No. Questions
1 What is Routing?
2 How many types of routes are there?
3 What is web php?
4 What is api php?
5 What is channels php?
6 What is console-php?
2 What is Controller?
3 What are Views?
4 What is a Model?
5 What is Request-Response?
6 When are Migrations?
7 What are Seeders?
8 What are Service Providers?
9 What is Middleware?
10 What is ORM?
11 What is Eloquent?
12 What is Query Builder?
13 What are Facades?
14 What is Repository Pattern?
15 What is Authentication using Passport CSRF XSRF?
16 What is Unit testing?
17 What is Caching?
18 How to setup Emails?
19 What are Queues?
20 What are Jobs?
21 What are Advanced Eloquent and Query Builder?
22 Which is Error management?
23 How to create an API?
24 What are Events?
25 What are Listeners?
26 What are Payments and cashier?
27 What is Test Driven Development?
28 What is Package development?
29 What are Laravel Scout search and Algolia?
30 What is Socialite and Auth?
31 What is Vue-js?
32 How to connect Laravel with other SQL databases?
33 How to connect Laravel with non-SQL databases?
34 What is Lumen?
35 What is Redis?
36 What is Memcache?
37 What is Horizontal scaling?
38 What is Vertical scaling?
39 What is Single Page Application in Laravel?
40 What are Microservices in Laravel?
41 What is CSRF and JWT token?
42 What is Service Oriented Architecture in Laravel?
43 What are Validations and custom validations?
44 What is Composer?
45 What is Symfony?
46 What is Route caching?
47 What are Default packages: Cashier,Envoy,Passport,Scout,Socialite,Horizon?
48 What are Named routes?
49 What is Dependency injection in Laravel?
50 What are Laravel contracts?
51 What is Query log?
52 What are Laravel Traits?
53 What are Bundles in Laravel?
54 What are System requirements for Laravel?
55 What are Aggregate methods in query builder?
56 What is Singelton design pattern?
57 What is Reverse routing?
58 What are Popular composer packages?
59 How to get the data from more than 3 table without using a join?
60 List some artisan commands
61 What are Sessions?
62 What are Cookies?
63 What is Current version of PHP, MySQL, Laravel, MongoDB etc?
64 Describe design architecture of an app?
65 What are SQL Injections?
66 How to call static methods?
67 How to achieve multiple DB hosts?
68 What is Abstract class?
69 What are Default ports for MySQL Email etc?
70 Explain Joins
71 Explain Unions
72 How mongodb is better than relational databases?
73 What is mongodb?
74 What is default session time?
75 How to create hooks in Laravel?
76 What is csrf token and xss attack?
77 Select highest and nth highest salary from DB
78 Write a join
79 Write a union
80 Write a complex query?
81 Explain an apps DB architecture ?
82 What is Difference between PHP 5 and 4?
83 What is the difference among various php versions?
84 What is the difference among various mysql versions?
85 What is the difference among various Laravel versions?
86 How to add AWS plugin in PHP?
87 What are design patterns?
88 What is the difference between GET and POST
89 Which is fast between GET and POST?
90 Explain 4 basics of OOP
91 What is diference between abstract class and interface?
92 What is MVC Framework?
93 Write CRUD in Laravel Eloquent
94 Explain CURL and SOAP?
95 In MySql we use many types of engines which one is faster and why?
96 What are Triggers?
97 What are Procedures
98 What are some new feaatures of Laravel X?
99 What are some new features of PHP X?
100 Explain Difference between session and cookies?
101 Merge 2 arrays with duplicate
102 Find the count of vowel and consonants
103 Explain AWS Services
104 How to do Web scraping?
105 Explain require and require once difference
106 Explain include and require diffrence
107 Directory structure of Laravel
108 How to install Laravel via composer?
109 Which ORM are being used by laravel?
110 List types of relationships available in Laravel Eloquent?
111 How to enable maintenance mode in Laravel?
112 What is the purpose of using dd() function in laravel?
113 How do you register a Service Provider?
114 Explain Laravel framework Architecture
115 Helper Functions
116 What is Fillable Attribute in a Laravel Model?
117 What is Guarded Attribute in a Laravel Model?
118 What are Closures in Laravel?
119 How to get Logged in user info in Laravel?
120 What is Laravel Elixir?
121 What is Laravel Mix?
122 How can you display HTML with Blade in Laravel?
123 List out databases that laravel supports?
124 How to use custom table in Laravel Model?
125 How To Use Select Query In Laravel? Eloquent and QB?
126 What are Accessors and Mutators in Eloquent and why should you use them?
127 How do I log an error?
128 What is Monolog library in Laravel?
129 Exceptions are handled by which class in Laravel?
130 What is Serialization in Laravel?
131 What is Response in Laravel?
132 What is Response Macros in Laravel?
133 What is Rate Limiting OR Throttle in Laravel?
134 What is Lazy vs Eager Loading in Laravel?
135 How to get current environment in Laravel?
136 How to use custom table in Laravel Model?
137 What is Binding?
138 Explain Binding A Singleton?
139 Explain Binding Instances?
140 Explain Binding Primitives?
141 Explain Contextual Binding and how does it work?
142 What is Tagging?
143 Explain Extending Bindings?
144 What is the make Method?
145 How to clear cache in Laravel?
146 What is CSRF token?
147 How will you explain homestead in Laravel?
148 How can we get the user's IP address in Laravel?
149 How will you create a helper file in Laravel?
150 How can we create a record in Laravel using eloquent?
151 How can we get the user's IP address in Laravel?
152 What is faker in Laravel?
153 What are active records?
154 What are the difference between insert() and insertGetId() in laravel?
155 Talk about Laravel Vapor Compatibility
156 What is Semantic Versioning?
157 What are Jobs and Middleware?
158 Talk about Laravel User Interface (UI)
159 Talk about Eloquent Subquery Enhancements?
160 What are improved Authorization Responses?
161 What are lazy collections?
162 How to make a constant and use globally?
163 How to remove /public from URL in laravel?
164 What are the difference between soft delete & delete in Laravel?
165 How we can upload files in laravel?
166 How to create real time sitemap.xml file in Laravel?
167 How to use skip() and take() in Laravel Query?
168 What is tinker in laravel?
169 What is a REPL?
170 How to use multiple 'OR' condition in Laravel Query?
171 Please write some additional where Clauses in Laravel?
172 How to check column is exists or not in a table using Laravel?
173 What is eager loading in Laravel?
174 How to generate application key in laravel?
175 What is LTS version of Laravel?
176 How to use GROUP_CONCAT() with JOIN in Laravel?
177 How to extend login expire time in Auth?
178 How to extend a layout file in laravel view?
179 How do you use yield()?
180 How to redirect form controller to view file in laravel?
181 How to get current route name?
182 What is ACL in laravel?
183 How to check Ajax request in Laravel?
184 How to check if value is sent in request?
185 Laravel String Helper functions?
186 Laravel Array Helper functions?
187 How to exclude a route with parameters from CSRF verification?
188 What are policies classes?
189 How to rollback last migration?
190 What do you mean by Laravel Dusk?
191 Explain Laravel echo
192 What is namespace in Laravel?
193 What is Laravel Forge?
194 State the difference between CodeIgniter and Laravel.
195 What is an Observer?
196 What is the use of the bootstrap directory?
197 What is the default session timeout duration?
198 Explain API.PHP route
199 Define hashing in Laravel
200 What is Localization?
201 Explain the concept of encryption and decryption in Laravel.
202 How to share data with views?
203 How to generate a request in Laravel?
204 I just have installed a fresh version of Laravel 5, and I have the white screen of death. What’s wrong?
205 How to assign a variable value for all view file?
206 How to make a constant and use globally?
207 How to check current installed version of Laravel?
208 What does "composer dump-autoload" do?
209 What is Kept in vendor directory of Laravel?
210 What does PHP compact function do?
210 What is APP_KEY used for?
211 What are Laravel facades?
212 What directories that need to be writable laravel installation?
213 How to check current Laravel version using CLI?
214 Why prefer Laravel over other frameworks?
215 What are service containers?
216 Write CRUD in Laravel Eloquent?
217 Write CRUD in Laravel Query Builder?
218 How to install laravel via composer?
219 What are Eloquent collections?
220 Output a raw query using eloquent/query builder
221 How to create custom helper functions
222 How to check installed extensions in CLI and web for PHP?
223 How to create multiple where clause in eloquent?
  1. What is Routing?

When a user enters a URL, it gets send to a routes file. Laravel contains a routes.php file where it matches it with the right controller/view.

Below is an example route from routes/web.php. You can can call site.exension/foo and it will bring the result.

Route::get('foo', function () {
    return 'Hello World';
});

⬆ Back to Top

  1. How many types of routes are there?

There are four types of routes in routes.php file,

A. web.php 

B. api.php

C. console.php

D. broadcast.php

⬆ Back to Top

  1. What is web php?

web.php used for web routes. Like example.com/test

Route::get('/test', function () {
    $path = storage_path() . "/app/json/options/docs.json";
    return view('skin/dev-wireframe', array('menu' => json_decode(file_get_contents($path), true)));
});

⬆ Back to Top

  1. What is api php?

    The place where we write API route for mobile and API usage. Like http://localhost:8080/api/test

    Route::get('/test', function () {
        $path = storage_path() . "/app/json/options/docs.json";
        return view('skin/dev-wireframe', array('menu' => json_decode(file_get_contents($path), true)));
    });
    
  2. What is channels php?

    It is used for broadcasting

⬆ Back to Top

  1. What is console php?

    Used as routes for commands

    ⬆ Back to Top

  2. What is Controller?

    Controller is the place where we write the logic of the program. Placed in app/Http/Conrollers

    <?php namespace App\Http\Controllers;
    
    use App\Http\Controllers\Controller;
    
    class UserController extends Controller {
    
        /**
         * Show the profile for the given user.
         *
         * @param  int  $id
         * @return Response
         */
        public function showProfile($id)
        {
            return view('user.profile', ['user' => User::findOrFail($id)]);
        }
    
    }
    

    ⬆ Back to Top

  3. What are Views?

Views is the fornt end of Laravel. Stored in resources/views.

```
<html>
    <body>
        <h1>Hello, {{ $name }}</h1>
    </body>
</html>
```

⬆ Back to Top

  1. What is a Model?

    A model is where you write the database logic. Stored in /app

  2. What is Request-Response?

    When we type a URL, a request is sent to the server. The server goes from /public to bootstrap folder from which is goes to the routes file. The route files sends it the right controller/view.

    ⬆ Back to Top

  3. What are Migrations?

    Migrations help us keep SQL tables in code. When we have to setup the DB, we just run the migration.

    ⬆ Back to Top

  4. What are Service Providers?

    Service providers are responsible for booting and configuration (binding all resources.)

    ⬆ Back to Top

  5. What is Middleware?

    Middleware checks for authentication.

    ⬆ Back to Top

  6. What is ORM?

    Object oriented and Model based way of DB query

    ⬆ Back to Top

  7. What is Eloquent?

    The ORM wrapper Laravel uses is called Eloquent. Every table has a model associated with it.

⬆ Back to Top

  1. What is Query Builder?

A database wrapper that makes it easy to access DB.

⬆ Back to Top

  1. What are Facades?

    Facades are used to hide implementation details and complexities from end user making him/her feel like interacting with a black box.

⬆ Back to Top

  1. What is Repository Pattern?

    Repository pattern is used to create templates where implementation details are left to be implemented in child classes. It helps with further expansion of code and avoid bottlenecks in class updation.

⬆ Back to Top

  1. What is Authentication using Passport?

    Passport provides a better way to create API.

⬆ Back to Top

  1. What Unit testing?

    Testing every function

⬆ Back to Top

  1. What is Caching?

    Configured using config/cache.php. Used for database caching. Popular ways Redis and Memcache.

⬆ Back to Top

  1. What is Unit Testing?

    Writing a test for every unit (function or class) you write.

⬆ Back to Top

  1. How to setup Emails?

    Using PHP's mail() function amnd Laravel's sendmail() function. You can custoimize it using templates.

⬆ Back to Top

  1. What are Queues?

    Queue is a line of jobs to be proccessed. You can create multiple queues which is multiple lines of jobs ⬆ Back to Top

  2. What are Jobs?

    Job is a task being performed in the background.

⬆ Back to Top

  1. How to setup Emails?

Use Laravel's sendmail() function and create a mail template.

⬆ Back to Top

  1. What are Advanced Eloquent and Query Builder?

    Complex eloquent queries are called advanced eloquent. Query builder is wrapper for database queries.

⬆ Back to Top

  1. Which is Error management?

Error handling is managing exception in a Laravel application.

⬆ Back to Top

  1. How to create an API?

Use api.php. Link will be x.com/api/slug

⬆ Back to Top

  1. What are Events?

You get notified when an action is triggered.

⬆ Back to Top

  1. What are Listeners?

    Which listen to the events.

⬆ Back to Top

  1. What are Payments and cashier?

    Payment processing is difficult. Cashier is a package which makes it easy. Its installed using composer.

⬆ Back to Top

  1. What is Test Driven Development?

    Test is written first and then the function is written.

⬆ Back to Top

  1. What is Package development?

    Larvel uses composer which gets packages. You can develop your own package and submit.

⬆ Back to Top

  1. What are Laravel Scout search and Algolia?

https://laravel.com/docs/5.8/scout

⬆ Back to Top

  1. Socialie and Auth?

    Socialite is Social login for Laravel. Auth is Laravel's authentication.

⬆ Back to Top

  1. What is Vue-js?

    In easy way to do SPA where you can change state.

⬆ Back to Top

  1. How to connect Laravel with other SQL databases?

    Go to config/database.php

⬆ Back to Top

  1. How to connect Laravel with non-SQL databases?

Add the entry to config/database.php

⬆ Back to Top

  1. What is Lumen?

    Lumen is the lightweight version of Laravel used usually for making microservices.

⬆ Back to Top

  1. What is Redis?

    Key-value database making query faster.

⬆ Back to Top

  1. What is Memcache?

    Key-value database making query faster.

⬆ Back to Top

  1. What is Horizontal scaling?

    By adding more servers we scale horizontally.

⬆ Back to Top

  1. What is Vertical scaling?

    By increasing the size of the same server we scale vertically.

⬆ Back to Top

  1. What is Single Page Application in Laravel?

    There is single URL. The assets are loaded once and only content keeps changing using JSON request. Its not great for SEO but there are workarounds to create virtual URL.

⬆ Back to Top

  1. What are Microservices in Laravel?

    There are many services which are similar sized. Each performs exactly one function and they talk to each other.

⬆ Back to Top

  1. What is CSRF and JWT token?

    CSRF and JWT tokens are used to make sure the action is performed by the user. If there is no token, someone can give a link to user to click or hide it behind some action and him do what the hacker wants. A JWT token is hidden in the request while CSRF token is not.

⬆ Back to Top

  1. What is Service Oriented Architecture in Laravel?

    There are many services which are similar sized. Each performs exactly one function and they talk to each other.

⬆ Back to Top

  1. What are Validations and custom validations?

    Validations are used to make sure input is of the kind function wanted. Custom validators are custom made valiators.

⬆ Back to Top

  1. What is Composer?

    Composer is PHP's package manager.

⬆ Back to Top

  1. What is Symfony?

    Symfony is a framework Laravel is inspired from.

⬆ Back to Top

  1. What is Route caching?

    Caching of routes to make going to routes faster. Command: php artisan route:cache

⬆ Back to Top

  1. What are Default packages?

    Cashier, Envoy, Passport, Scout, Socialite, Horizon etc

⬆ Back to Top

  1. What are Named routes?

    You can give route a name using a parameter.

⬆ Back to Top

  1. What is Dependency injection in Laravel?

    Laravel injects dependencies as function parameters. Read more: https://medium.com/a-young-devoloper/how-laravel-injects-our-dependencies-14e1b1a044e

⬆ Back to Top

  1. What are Laravel contracts?

They provide insstructions to interact with a facade.

https://laravel.com/docs/7.x/contracts

⬆ Back to Top

  1. What is Query log?

You can enable logging queries and Laravel will record the queries which were run.

⬆ Back to Top

  1. What are Laravel Traits?

    They solve diamond problem which is when you have to inherit from two classes.

⬆ Back to Top

  1. What are Bundles in Laravel?

    Used for grouping stuff like route groups (CRUD in one line.)

⬆ Back to Top

  1. What are System requirements for Laravel?

    PHP version, MySQL, PHP packages mentioned on Laravel.com, apache server

⬆ Back to Top

  1. What are Aggregate methods in query builder?

    Max, min, sum etc

$price = DB::table('orders')->max('price');

⬆ Back to Top

  1. What is Singelton design pattern?

    A single object of a class is created throughout the lifecycle.

⬆ Back to Top

  1. What is Reverse routing?

To generate the process of generating the URL which leads to a route. Its used in MVC apps. You can use it using named routes in laravel.

⬆ Back to Top

  1. What are Popular composer packages?

    Guzzle

⬆ Back to Top

  1. How to get the data from more than 3 table without using a join ?

    Answer: Subquery, union.

⬆ Back to Top

  1. List some artisan commands

    php artisan list
    php artisan make:migrate
    php artisan make:controller
    php artisan make:model
    php artisan config:clear
    php artisan serve
    

⬆ Back to Top

  1. What are Sessisons?

    Session is data related to a specific user.

⬆ Back to Top

  1. What are Cookies?

    Cookies is generalized data.

⬆ Back to Top

  1. What is Current version of PHP MySQL Laravel MongoDB etc?

    PHP: PHP 7.4 MySQL: 7 Laravel: 6 MongoDB: 4

⬆ Back to Top

  1. Describe design architecture of an app?

    There are three layers

    1. Presentation layer: Front end
    2. Business layer: Backend and logic
    3. Data layer: Model and database

⬆ Back to Top

  1. What are SQL Injections?

    Its a hacking trick used to complete a SQL query by filling a form content and placing query parts inside the form.

⬆ Back to Top

  1. How to call static methods?

    Using :: before function name instead of ->.

⬆ Back to Top

  1. How to achieve multiple DB hosts?

    Define the new DB in env or config/database.php and use it.

⬆ Back to Top

  1. What is Abstract class?

    A class which is just a template i.e has no defination but just declaration.

⬆ Back to Top

  1. What are Default ports for MySQL, Email, etc?

    http: 80 MYSQL: 3306 Email: 587

⬆ Back to Top

  1. Explain Joins

    There are 4 types of joins,

    1. Inner Join
    2. Outer Join
    3. Left Join
    4. Right Join

⬆ Back to Top

  1. Explain Unions

    Union horizontally joins tables together i.e the records are added into the same columns.

⬆ Back to Top

  1. How mongodb is better than relational databases?

    It is faster and it stores data in JSON form so you can enter multiple types of data without being dependent on the data being consistent in type.

⬆ Back to Top

  1. What is mongodb?

It is a NO SQL key value based database.

⬆ Back to Top

  1. What is default session time?

1 hour.

⬆ Back to Top

  1. How to create hooks in Laravel?

    https://stackoverflow.com/questions/36226021/hooks-in-laravel-5

⬆ Back to Top

  1. What is csrf token and xss attack?

CSRF and JWT tokens are used to make sure the action is performed by the user. If there is no token, someone can give a link to user to click or hide it behind some action and him do what the hacker wants.

⬆ Back to Top

  1. Select highest and nth highest salary from DB

    SELECT name, salary 
    FROM #Employee e1
    WHERE N-1 = (SELECT COUNT(DISTINCT salary) FROM #Employee e2
    WHERE e2.salary > e1.salary)
    

    https://javarevisited.blogspot.com/2016/01/4-ways-to-find-nth-highest-salary-in.html

⬆ Back to Top

  1. Write the 4 joins

    1. Inner join
    2. Outer join
    3. Left join
    4. Right join

⬆ Back to Top

  1. Write a union

    SELECT expression1, expression2, ... expression_n
    FROM tables
    [WHERE conditions]
    UNION [DISTINCT]
    SELECT expression1, expression2, ... expression_n
    FROM tables
    [WHERE conditions];
    

⬆ Back to Top

  1. Write a complex query?

Like a 3 tables joined.

⬆ Back to Top

  1. Explain an apps DB architecture

Uber's DB arcitecture.

⬆ Back to Top

  1. What is Difference between PHP 5 and 4?

    PHP 5 has OOP.

⬆ Back to Top

  1. What is the difference among various php versions?

    PHP 4: No OOP PHP 5: OOP PHP 7: Faster speed

⬆ Back to Top

  1. What is the difference among various Laravel versions?

    Directory structure

⬆ Back to Top

  1. How to add AWS plugin in PHP?

    Using AWS SDK.

⬆ Back to Top

  1. What are design patterns?

    They are well known solutions to common problems every developer faces.

⬆ Back to Top

  1. What is the difference between GET and POST

    GET is used for retriving data POST is used to perform a change i.e action

⬆ Back to Top

  1. Which is fast between GET and POST?

    GET is used for retriving data POST is used to perform a change i.e action

  2. Explain 4 basics of OOP

    Inheritance Polymorphism Encapsulation Abstraction

⬆ Back to Top

  1. What is diference between abstract class and interface?

https://javapapers.com/core-java/abstract-and-interface-core-java-2/difference-between-a-java-interface-and-a-java-abstract-class/

⬆ Back to Top

  1. What is MVC Framework?

    It provides separation of concerns by separating the code into 3 parts,

    1. Model: Database logic
    2. View: Frontend logic
    3. Controller: Backend logic

⬆ Back to Top

  1. Create a project with CRUD, one algorithm logic and insert data in db for testing.

    ...

⬆ Back to Top

  1. In MySql we use many types of engines which one is faster and why?

    There are two main types of engines, 1.InnoDB 2.MyISAM InnoDB is faster.

⬆ Back to Top

  1. What are Triggers?

    DB::unprepared() is used for it.

    php artisan make:migration create_trigger    
    

⬆ Back to Top

  1. What are Procedures

    Stored procedures are SQL code in tables. It is called and executed inside tables.

⬆ Back to Top

  1. What are some new feaatures of Laravel X?

https://medium.com/@samwatsonets/difference-between-laravel-6-0-and-its-previous-versions-efb2829d0f55

⬆ Back to Top

  1. What are some new features of PHP X?

    PHP 7.4 brings, 1. 2.

⬆ Back to Top

  1. Explain Difference between session and cookies?

Cookies is data sent with every request. It is usually generalized for all. Session is data related to a specific user.

⬆ Back to Top

  1. Merge 2 arrays with duplicate

```
array_unique(array_merge($array1,$array2), SORT_REGULAR);

```

⬆ Back to Top

  1. Find the count of vowel and consonants

$str="Find the count of vowel and consonants"
$i=0; $vowel=0; $const=0;
foreach ($char in $str)
{
    if(($char==" ") || ($i==0))
        {
           if(($str[$i+1]==a) || ($str[$i+1]==e) || ($str[$i+1]==i) || ($str[$i+1]==o) || ($str[$i+1]==u))
           $vowel++;
           else
           $const++;
        }
        $i++;
}

⬆ Back to Top

  1. Explain AWS Services

AWS has 20 main categories and 150 sub-categories of items. For hosting, EC2 is a well known server type.

⬆ Back to Top

  1. How to do Web scraping?

Composer has built in packages for it. They may get stopped due to IP usage (no of connections

⬆ Back to Top

  1. Explain require and require once difference

In require, you can use require multiple times for the same file. It will add the file multiple times while require_once will only require it once.

⬆ Back to Top

  1. Explain include and require diffrence

In include() the script will run even if the file is not found while in require it will stop if file required is not found.

⬆ Back to Top

  1. Directory structure of Laravel

```
/bootsrtrap
/public
/routes
/resources
/config
/app
.env
```
etc

⬆ Back to Top

  1. How to install Laravel via composer?

```
composer create-project --prefer-dist laravel/laravel blog "5.8.*"
```

⬆ Back to Top

  1. Which ORM are being used by laravel?

Eloquent

⬆ Back to Top

  1. List types of relationships available in Laravel Eloquent?

One To One
One To Many
One To Many (Inverse)
Many To Many
Has Many Through
Polymorphic Relationships
One To One
One To Many
Many To Many
Custom Polymorphic Types

⬆ Back to Top

  1. How to enable maintenance mode in Laravel?

```
php artisan down
```

⬆ Back to Top

  1. What is the purpose of using dd() function in laravel?

dd() is dump and die. It prints the variable/array and exits the script.

⬆ Back to Top

  1. How do you register a Service Provider?

Inside `config/app.php`
```
'providers' => [

    /*
     * Laravel Framework Service Providers...
     */
    Illuminate\Auth\AuthServiceProvider::class,
    Illuminate\Broadcasting\BroadcastServiceProvider::class,
    ...
```

⬆ Back to Top

  1. Explain Laravel framework Architecture

⬆ Back to Top

  1. Helper Functions

Common function which you can use in many classes are stored in helper functions.

⬆ Back to Top

  1. What is Fillable Attribute in a Laravel Model?

Which can be mass assigned.

⬆ Back to Top

  1. What is Guarded Attribute in a Laravel Model?

Which can't be mass assigned.

⬆ Back to Top

  1. What are Closures in Laravel?

a closure gives you access to an outer function's scope from an inner function

⬆ Back to Top

  1. How to get Logged in user info in Laravel?

```
$user = auth()->user();
print_r($user);
```

⬆ Back to Top

  1. What is Laravel Elixir?

Used for compiling JS.

⬆ Back to Top

  1. What is Laravel Mix?

Used for compiling JS.

⬆ Back to Top

  1. How can you display HTML with Blade in Laravel?

    {!! $text !!}

⬆ Back to Top

  1. How to install laravel via composer ?

    composer create-project laravel/laravel name

⬆ Back to Top

  1. List out databases that laravel supports?

    Laravel supports four database systems: MySQL, Postgres, SQLite, and SQL Server.

⬆ Back to Top

  1. How to use custom table in Laravel Model?

By mentoning the name of the table in `$table` variable

⬆ Back to Top

  1. How To Use Select Query In Laravel? Eloquent and QB?

QB: $users = DB::table('users')->select('name', 'email as user_email')->get();
Eloquent: $users = User::all();
  1. What are Accessors and Mutators in Eloquent and why should you use them?

https://laravel.com/docs/4.2/eloquent#accessors-and-mutators

⬆ Back to Top

  1. How do I log an error?

https://laravel.com/docs/5.2/errors

⬆ Back to Top

  1. What is Monolog library in Laravel?

Helps with logging.

⬆ Back to Top

  1. Exceptions are handled by which class in Laravel?

    App\Exceptions\Handler class.

⬆ Back to Top

  1. What is Serialization in Laravel?

https://laravel.com/docs/5.8/eloquent-serialization

⬆ Back to Top

  1. What is Response in Laravel?

When we make a request , we get a responsse.

⬆ Back to Top

  1. What is Response Macros in Laravel?

https://laravel.com/docs/5.8/responses#response-macros

⬆ Back to Top

  1. What is Rate Limiting OR Throttle in Laravel?

https://www.cloudways.com/blog/laravel-and-api-rate-limiting/

⬆ Back to Top

  1. What is Lazy vs Eager Loading in Laravel?

https://laravel.com/docs/5.8/eloquent-relationships

⬆ Back to Top

  1. How to get current environment in Laravel?

https://stackoverflow.com/questions/14935846/laravel-4-how-can-i-get-the-environment-value

⬆ Back to Top

  1. How to use custom table in Laravel Model ?

$table=""

⬆ Back to Top

  1. What is Binding?

https://stackoverflow.com/questions/49348681/what-is-a-usage-and-purpose-of-laravels-binding

⬆ Back to Top

  1. Explain Binding A Singleton?

https://stackoverflow.com/questions/25229064/laravel-difference-appbind-and-appsingleton

⬆ Back to Top

  1. Explain Binding Instances?

https://stackoverflow.com/questions/40767040/how-laravels-container-binding-mechanisms-differ

⬆ Back to Top

  1. Explain Binding Primitives?

https://stackoverflow.com/questions/40767040/how-laravels-container-binding-mechanisms-differ

⬆ Back to Top

  1. Explain Contextual Binding and how does it work?

https://stackoverflow.com/questions/40767040/how-laravels-container-binding-mechanisms-differ

⬆ Back to Top

  1. What is Tagging?

Giving your binding a name.

⬆ Back to Top

  1. Explain Extending Bindings?

    https://stackoverflow.com/questions/40767040/how-laravels-container-binding-mechanisms-differ

⬆ Back to Top

  1. What is the make Method?

Makes controller, view, route, group and other items in artisan.

⬆ Back to Top

  1. How to clear cache in Laravel?

php artisan cache:cleaer

⬆ Back to Top

  1. What is CSRF token?

    Protects against cross site attack

⬆ Back to Top

  1. How will you explain homestead in Laravel?

Virtual box for vagrant

⬆ Back to Top

  1. How can we get the user's IP address in Laravel?

Request::ip();

⬆ Back to Top

  1. How will you create a helper file in Laravel?

https://tutsforweb.com/creating-helpers-laravel/

⬆ Back to Top

  1. How can we create a record in Laravel using eloquent?

    $flight = new Flight;
    
    $flight->name = $request->name;
    
    $flight->save();
    

⬆ Back to Top

  1. How can we get the user's IP address in Laravel?

Request::ip();

⬆ Back to Top

  1. What is faker in Laravel?

    Used to generate dummy data

⬆ Back to Top

  1. What are active records?

A design pattern which masks SQL queries to make database CRUD operations easy.

⬆ Back to Top

  1. What are the difference between insert() and insertGetId() in laravel?

insert() only inserts
insertGetId() inserts and returns id of last added item

⬆ Back to Top

  1. Talk about Laravel Vapor Compatibility

https://vapor.laravel.com/

⬆ Back to Top

  1. What is Semantic Versioning?

Major version . Minor version . Bug fix

⬆ Back to Top

  1. What are Jobs and Middleware?

Jobs:
Middleware:

⬆ Back to Top

  1. Talk about Laravel User Interface (UI)

It uses Blade Templating Engine

⬆ Back to Top

  1. Talk about Eloquent Subquery Enhancements?

https://laravel-news.com/eloquent-subquery-enhancements

⬆ Back to Top

  1. What are improved Authorization Responses?

https://fullstackworld.com/post/what-is-new-to-laravel-6

⬆ Back to Top

  1. What are lazy collections?

https://laravel.com/docs/6.x/collections#lazy-collection-introduction

⬆ Back to Top

  1. How to make a constant and use globally?

https://medium.com/@panjeh/laravel-define-global-constants-config-php-file-5d6a9900bb6e

⬆ Back to Top

  1. How to remove /public from URL in laravel?

    Rename server.php in your Laravel root folder to index.php Copy the .htaccess file from /public directory to your Laravel root folder.

⬆ Back to Top

  1. What are the difference between soft delete & delete in Laravel?

    https://blog.hashvel.com/posts/eloquent-orm-soft-delete-permanent-delete-in-laravel/

⬆ Back to Top

  1. How we can upload files in laravel?

Using `Form` class.
```
<html>
   <body>
      <?php
         echo Form::open(array('url' => '/uploadfile','files'=>'true'));
         echo 'Select the file to upload.';
         echo Form::file('image');
         echo Form::submit('Upload File');
         echo Form::close();
      ?>
   </body>
</html>
```

⬆ Back to Top

  1. Why are Redux state functions c166. ### How to create real time sitemap.xml file in Laravel?

Make a controller to loop through all pages and list them. Make a route to it.

⬆ Back to Top

  1. How to use skip() and take() in Laravel Query?

https://www.bestinterviewquestion.com/question/how-to-use-skip-take-in-laravel-query-kcle83908l2

⬆ Back to Top

  1. What is tinker in laravel?

Tinker is command line code functionality where you can write Laravel code in CLI.

⬆ Back to Top

  1. What is a REPL?

https://en.wikipedia.org/wiki/Read%E2%80%93eval%E2%80%93print_loop

⬆ Back to Top

  1. How to use multiple 'OR' condition in Laravel Query?

Use it as an array in a single or function.

⬆ Back to Top

  1. Please write some additional where Clauses in Laravel?

Use it as an array inside where function.

⬆ Back to Top

  1. How to check column is exists or not in a table using Laravel?

SELECT that column and chekc if result is not null

⬆ Back to Top

  1. What is eager loading in Laravel?

https://medium.com/@sdkcodes/laravel-eloquent-eager-loading-9596b15e8b5d

⬆ Back to Top

  1. How to generate application key in laravel?

php artisan key:generate

⬆ Back to Top

  1. What is LTS version of Laravel?

LTS version is a version where the support is longer i.e it gets longer fixes and support and is a stable version.

⬆ Back to Top

  1. How to use GROUP_CONCAT() with JOIN in Laravel?

https://www.bestinterviewquestion.com/question/how-to-use-group-concat-with-join-in-laravel-cht1n5023bz

⬆ Back to Top

  1. How to extend login expire time in Auth?

Change the minutes in config\session.php file.

⬆ Back to Top

  1. How to extend a layout file in laravel view?

@extends('name.app')

⬆ Back to Top

  1. How do you use yield()?

    @yield('navigation')

⬆ Back to Top

  1. What is ACL in laravel?

Package that manages user permissions

⬆ Back to Top

  1. How to check Ajax request in Laravel?

https://stackoverflow.com/questions/29231587/laravel-check-if-ajax-request

⬆ Back to Top

  1. How to check if value is sent in request?

dd($Request)

⬆ Back to Top

  1. Laravel String Helper functions?

https://laravel.com/docs/5.8/helpers

⬆ Back to Top

  1. Laravel Array Helper functions?

https://laravel.com/docs/5.8/helpers

⬆ Back to Top

  1. How to exclude a route with parameters from CSRF verification?

https://stackoverflow.com/questions/48062083/laravel-5-4-exclude-a-route-with-parameters-from-csrf-verification

⬆ Back to Top

  1. What are policies classes?

https://laravel.com/docs/5.7/authorization#policy-methods

⬆ Back to Top

  1. How to rollback last migration?

Run migration rollback. If you want to rollback more than one steps, give the steps count.

⬆ Back to Top

  1. What do you mean by Laravel Dusk?

https://laravel.com/docs/5.8/dusk

⬆ Back to Top

  1. Explain Laravel echo

Used with broadcasting and sockets.

⬆ Back to Top

  1. What is namespace in Laravel?

Identifies a code block and treats it separate fropm the rest so same name confusions don't occur.

⬆ Back to Top

  1. What is Laravel Forge?

Laravel managed cloud hosting

⬆ Back to Top

  1. State the difference between CodeIgniter and Laravel.

CodeIgniter is an older framework and Laravel is a much advanced framework.

⬆ Back to Top

  1. What is an Observer?

https://codebriefly.com/brief-understanding-on-laravel-observers/

⬆ Back to Top

  1. What is the use of the bootstrap directory?

Laravel starts from there.

⬆ Back to Top

  1. What is the default session timeout duration?

120 minutes

⬆ Back to Top

  1. Explain API.PHP route

It is used for creating API. Its url is /api/slug

⬆ Back to Top

  1. Define hashing in Laravel

https://laravel.com/docs/5.7/hashing

⬆ Back to Top

  1. What is Localization?

https://medium.com/@nedsoft/laravel-localization-made-simple-8ee4a34731e7

⬆ Back to Top

  1. How to share data with views?

Pass it from the routes. To add for all views: https://laravel.com/docs/5.7/views#sharing-data-with-all-views

⬆ Back to Top

  1. How to generate a request in Laravel?

Enter a route. It will go to the routes file to match the route and return a response.

⬆ Back to Top

  1. I just have installed a fresh version of Laravel 5, and I have the white screen of death. What’s wrong?

You might see the white screen of death because of not enough permissions in folders. Try changing permissions of `/public`, `/vendor`, `/storage` folders.

⬆ Back to Top

  1. How to assign a variable value for all view file?

```
        public function __construct() {       

            $this->middleware(function ($request, $next) {              

                $name = session()->get('businessinfo.name');  // get value from session

                View::share('user_name', $name);                   // set value for all View

                View::share('user_email', session()->get('businessinfo.email'));            

                return $next($request);

            });

             }


     
```

⬆ Back to Top

  1. How to make a constant and use globally?

Create it in the .env file

  1. How to check current installed version of Laravel?

See `composer.json` file.

⬆ Back to Top

  1. What does "composer dump-autoload" do?

It just regenerates the list of all classes that need to be included in the project (autoload_classmap.php).

⬆ Back to Top

  1. What is Kept in vendor directory of Laravel?

Laravel dependencies. Their code.

⬆ Back to Top

  1. What does PHP compact function do?

Convert variables to array.

⬆ Back to Top

  1. What are Laravel facades?

...

⬆ Back to Top

  1. What directories that need to be writable laravel installation?

/public /bootstrap/cache /vendor

⬆ Back to Top

  1. How to check current Laravel version using CLI?

php artisan --version

⬆ Back to Top

  1. Why prefer Laravel over other frameworks?

https://blog.vanila.io/why-laravel-is-best-php-framework-98a2784d76dc?gi=a81f8fa92a65

⬆ Back to Top

  1. What are service containers?

The place where service providers are stored

⬆ Back to Top

  1. Write CRUD in Laravel Eloquent

CREATE:

     $flight = new Flight;

READ:

$flights = App\Flight::all();
foreach ($flights as $flight) {
    echo $flight->name;
}

UPDATE:

    $flight = new Flight;

    $flight->name = $request->name;

    $flight->save();

DELETE:

$flight->delete();

⬆ Back to Top

  1. Write CRUD in Laravel Query Builder

CREATE: DB::table('users')->insert( ['email' => 'john@example.com', 'votes' => 0] );

READ: $users = DB::table('users')->get();

UPDATE: DB::table('users') ->where('id', 1) ->update(['votes' => 1]);

DELETE: DB::table('users')->where('votes', '>', 100)->delete(); source: https://laravel.com/docs/5.8/queries

⬆ Back to Top

  1. What are Eloquent collections?

A way to get all of the data of a one or more models which might be required.

⬆ Back to Top

  1. Build a to-do application with Laravel backend and a frontend framework

--

⬆ Back to Top

  1. What are the day to day tasks of a Laravel developer?

    1. Creating APIs
    2. Write queries using Eloquent
    3. Write helper functions
    4. Installing required extensions for setting up Laravel
    5. Setting up docker
    6. Setting up homestead
    7. Vue
    8. Writing complex queries using eloquent
    9. Using design patterns to build scaleable solutions
    10. Tweak blade template.
    11. Create SPA
    12. Seed data into the database --

⬆ Back to Top

  1. Output a raw query using eloquent or query builder.

Two ways,

  1. Turn the DB logs on and check the last query run in it.
  2. add ->ToSQL() function after the query.

⬆ Back to Top

  1. How to create custom helper functions?

Create a helper.php file anywhere and place the functions in it

Add its location in the composer.json files area.

Run composer dump autoload

Answer here: https://stackoverflow.com/questions/28290332/best-practices-for-custom-helpers-in-laravel-5

⬆ Back to Top

  1. How to check installed extensions in CLI and web for PHP?

web: run phpinfo() function

cli: php -m

⬆ Back to Top

  1. How to create multiple where clause in eloquent?

Use a single where clause and give the parameters as array

  $query->where([
   ['column_1', '=', 'value_1'],
   ['column_2', '<>', 'value_2'],
   [COLUMN, OPERATOR, VALUE],
   ...
  ])
  1. How to clear all cache?

There are 4 cache in Laravel. Clear them all.

 php artisan key:generate
 
 php artisan config:cache
 
 php artisan cache:clear
 
 php artisan view:clear
 
 php artisan route:clear

About

Top Laravel Interview Questions & Answers

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published