Laravel Interview Questions
Laravel Interview Questions
o You can register service providers in the config/app.php configuration file that
contains an array where you can mention the service provider class name
Where will you define Laravel's Facades?
o All facades of Laravel have defined in Illuminate\Support\Facades namespace.
What is service container in Laravel?
o Service container is a tool used for performing dependency injection in Laravel.
Explain dependency injection and their types.
o It is a technique in which one object is dependent on another object. There are
three types of dependency injection: 1) Constructor injection, 2) setter injection, and
3) interface injection.
What is Localization?
o It is a feature of Laravel that supports various language to be used in the application.
A developer can store strings of different languages in a file, and these files are
stored at resources/views folder. Developers should create a separate folder for
each supported language.
How to share data with views?
o To pass data to all views in Laravel use method called share(). This method takes two
arguments, key, and value.
o Generally, share() method are called from boot method of Laravel application
service provider. A developer can use any service provider, AppServiceProvider, or
our own service provider.
Explain Eloquent in Laravel.
o Before understanding eloquent let’s first understand ORM - Object Relational
Mapping, it’s a programming technique for converting data between a relational
database and object-oriented programming, we can say it an object-relational
mapper as well.
o Eloquent is an ORM used in Laravel. It provides simple Active record implementation
working with the database. Each database table has their Model which used to
interact with the table. Eloquent provides many types of relationships:
o One to One
o Many to one
o One to Many
o Many to Many
o Has one through
o Has many through
Explain Laravel routing
o Laravel route helps to build SEO friendly request URL. Most basic Laravel route
accepts 2 parameters i.e. URI and closure.
o
o Route::get('hello', function () {
o return 'Hello World';
o });
o All Laravel routes are defined in route file in routes directory. For web interface
routes will be defined in routes/web.php whereas the routes in routes/api.php are
stateless and are assigned the api middleware group.
o
o Available Route Methods
o
o Route::get($uri, $callback);
o Route::post($uri, $callback);
o Route::put($uri, $callback);
o Route::patch($uri, $callback);
o Route::delete($uri, $callback);
o Route::options($uri, $callback);