1) What is Laravel?
Laravel is an open source PHP framework. It is used to design and develop web applications.
It is based on MVC (Model-View-Controller) design pattern.
It is created by Taylor Otwell in June 2011.
2) What are Advantages of Laravel?
There are various advantages of Laravel:
- Easy and consistent syntax
- Set-up process is easy
- customization process is easy
- code is always regimented with Laravel
3) What are the feature of Laravel5.0?
Laravel has following features :
- Method injection
- Contracts
- Route caching
- Events object
- Multiple file system
- Authentication Scaffolding
- dotenv - Environmental Detection
- Laravel Scheduler
4) Compare Laravel with Codeigniter?
Laravel |
Codeigniter |
It is a framework with expressive, elegant syntax. |
It is a powerful PHP framework |
Development is enjoyable, creative experience |
It provides simple toolkit to create full-featured web applications. |
Laravel is built for latest version of PHP |
Codeigniter is an older more mature framework |
It is more object oriented compared to CodeIgniter. |
It is less object oriented compared to Laravel. |
Laravel community is still small, but it is growing very fast |
Codeigniter community is large. |
5) How we can set database connection in Laravel?
In Laravel, we can set database connection into database.php file. It is stored into config folder.
'mysql' => [
'read' => [
'host' => 'localhost',
],
'write' => [
'host' => 'localhost'
],
'driver' => 'mysql',
'database' => 'database',
'username' => 'root',
'password' => '',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
'prefix' => '',
],
6) What are Bundles, Reverse Routing and The IoC container in Laravel?
Bundles: These are small functionalies which we can download to add in our web application.
Reverse Routing: It allows to change routes and application and also update all of the relevant links as per this link.
IoC container: It gives us control and a method for generating new objects and optionally instantiating and referencing singletons.
7) How can we create enable Query Logging?
We can create enable login query through the following command:
DB::connection()->enableQueryLog();
8) What is Composer in laravel?
In Laravel, composer is a dependency manager for PHP. It manage all the dependencies you require on a project by project basis. This means, it will pull in all the required libraries, dependencies and manage them all in one place.
9) What is Lumen in Laravel?
In Laravel, Lumen is a new project from Laravel creator
Taylor Otwell.
Lumen is a micro-framework. PHP has two other popular micro-frameworks:
10) How do we implement our own package in Laravel?
We can implement own package in laravel using the following steps:
- Package folder and name
- Composer.json file for the package
- Loading package via main composer.json and PSR-4
- Creating a Service Provider
- Create a Controller for your package
- Create our Routes.php file
11) What are the official packages provided by Laravel?
Laravel provides following official packages.
- Cashier
- Envoy
- Passport
- Scout
- Socialite
12) How can we install Laravel via composer ?
We can install Laravel via composer using given command:
composer create-project –prefer-dist laravel/laravel your-project-name
13) What is php artisan. List out some artisan commands?
PHP artisan is the command line interface or tool included with Laravel. It provides various types of commands that can help us, while we build our application easily. Here are some artisian command:
- php artisan list
- php artisan help
- php artisan tinker
- php artisan make
- php artisan –versian
- php artisan make modal modal_name
- php artisan make controller controller_name
14) How can we check current installed version of Laravel?
We can check current installed versions of Laravel using
php artisan –version command.
15) What are the methods provided by query builder in Laravel?
There are various methods provided by query builder in Laravel that are:
1) max()
Usage:$price = DB::table('orders')->max('price');
2)count()
Usage:$products = DB::table('products')->count();
3)min()
Usage:$price = DB::table('orders')->min('price');
4)avg()
Usage:$price = DB::table('orders')->avg('price');
5)sum()
Usage: $price = DB::table('orders')->sum('price');
15) What is an event in Laravel?
In Laravel, an event is an event or occurrence detected and handled by program.
Examples:
- A new user has registered
- A new comment is posted
- User login/logout
- New product is added.
16) What happen when we type "php artisan" in the command line?
Multiple command option will be appear.
17) Which template engine use Laravel?
Laravel use
blade template engine.
18) What are the default databases in Laravel?
MySQL is the default database in Laravel.
19) How can we register a service provide?
We can register a service provide by using following step:
- Open to config/app.php
- Find providers array if the various service provider.
- Add namespace 'Iluminate\Abc\ABCServiceProvider:: class,' to the end of the array
20) What is the use of implicit controllers?
An implicit controller is used to define a single route to handle every action in the controller.
Example:
Route::controller('base URI','');
21) What is the use of "composer dump -autoloader in Laravel"?
Composer dump-autoloader is used to reads the
composer.json file.
22) How can we get IP address in Laravel?
In Laravel, we can get IP address by using
ip() method.
Example
public function getUserIp(Request $request){
// Getting ip address of remote user
return $user_ip_address=$request->ip();
}
23) What are the types of relationship supported by Laravel?
There are seven types of relationship supported by Laravel that are given below:
- One To One
- One To Many
- One To Many (Inverse)
- Many To Many
- Has Many Through
- Polymorphic Relations
- Many To Many Polymorphic Relations
24) What is Laravel Query builder?
Laravel Query builder provide an interface to create and organize database queries.
25) What is Laravel Elixir?
Laravel Elixir provides API for define basic gulp tasks of Laravel application.
26) How can we enable maintenance model in Laravel 5?
We can enable maintenance model in Laravel by using given cod
//To enable maintenance mode
php artisan down
//To disable maintenance mode
php artisan up
27) Can Laravel be hacked?
No, Laravel can be hacked. It has inbuilt CSRF security.
28) Doest Laravel support PHP7?
Yes, PHP7 supports Laravel.
29) What is a trait in Laravel?
In Laravel, a traits is a group of method that we can include within another class. It is created to reduce the limitations of single inheritance.
30) How to create migration via artisan?
The given below command is used to create migration via artisan.
31) What is ORM in Laravel?
In Laravel, ORM stands for Object Relation Mapping. It is a programming technique for converting data between incompatible type systems in opps.
32) How to get logged in user info in Laravel?
Auth::User() function is used to get logged in user in Laravel.