What is Laravel?
Laravel is a PHP based web development framework and an Open Source.
It is the most popular MVC framework of the age and enriched with the latest technical specifications.
Laravel is different from other frameworks when it comes to performance because it has inbuilt security features, salable routing, flexibility.
What are Advantages of Laravel Framework?
Features of Laravel listed as :
- Supports MVC pattern of software development.
- Modular structure.
- Great Documentation and Number of forums.
- Dependency can be installed using composer tool.
- Easy to implement Authentication and Authorization.
- Inbuilt CSRF protection features.
- Powerful Artisan Command Line Interface.
- Featured with blade template engine, templates can be organize.
- Default Cache driver is configured and also support various cache drivers like Redis and Memcached.
- Debugging and use case features along with unit testing.
- Supports full-text search on Eloquent ORM modules.
- Schema Builder allows us to create database tables and migration.
- Best routing and session control features.
How can we install laravel via the composer?
Composer is a tool to install dependencies in any system.It is very easy to build dependency when we have to install third-party libraries.
Steps to install laravel using composer:
Step(1):Download and install composer from official website : https://getcomposer.org/download/
Step(2):Open CLI and run
composer create-project laravel/laravel test my-first-project
List some features of laravel 5.0 ?
Laravel is a powerful web development framework having features as :
- Laravel provide a modular structure to application which help us to build efficiently and ease the maintainability
- Includes features which help us to build test cases and debug the software and to meet the requirement.
- Laravel provide flexible routing feature to application, which leads to a better performance.
- Flexibility to run over many environment as local,production etc.
- Laravel is featured with ORM and Query Builder.It has rich library to query over complex conditions.
- It also maintains schema and build schema through PHP code.Help us to migrate the application.
- Laravel is also compatible to templating and uses Blade Template Engine.Blade is a Lightweight tempalting engine and provides hirerachical model to template designing.
- Laravel ease the methods of authentication and user management for application.
What is Artisan?
Artisan is a Command Line interface used by Laravel and It is very powerfull.It comes along with many powerful commands which help us to build scalable application modules in very less time.
List some artisan commands?
Some important artisan commands are listed:
- php artisan list : list all available artisan commands
- php artisan help migrate : display help screen for migrate command
- php artisan migrate –env=local : set the configuration environment as local
- php artisan –version : display the current version of laravel installation
What are Packages?
Packages are additional functionality which can be added to laravel easily.There are many types of packages which can be used according to requirement.
Name some of the packages used by Laravel?
List of some Laravel popular packages:
- Laravel Schema
What is routing?
Routing is a way to define flexible request URL for application. Laravel offers different routing methdods like get,post,put,delete,patch etc.
What is reverse routing in Laravel?
Reverse routing is a process to generate URL from the references given and route declaration at the time.
What is named routing in Laravel?
We can specify name for route, this is called Named Routing.We can access the name of a route that is running via the route name method.
What is database migration?
Laravel provide tools to migrate database tables from one server to another. We can create migration files. Migration has both import and rollback.A method up() is called to run the migration files and down() is called to rollback the changes.
How to create migration via artisan?
First of all we need to install migrate tools. Using this command we can install the migration tools.
php artisan migrate:install
artisan makes it very easy to create a migration:
php artisan migrate:make my_table_name
A migration file will be created for ‘my_table_name’ inside the application/migrations folder. We can execute all the migration using the following command line :
php artisan migrate application
How can we Rollback the last migration?
Run the artisan command to rollback the last migration:
php artisan migrate:rollback
How can we reset the migration?
Run the artisan command to reset the last migration:
php artisan migrate:reset
What are the Events in Laravel?
Events are the classes which are used to implement observer to listen the events triggered.Events are stored in app/Events folder.
What are service providers?
All the services need to be bootstrapped, so service provider perform this task in Laravel. According to Laravel official documentation “Service providers are the central place of all Laravel application bootstrapping. Your own application, as well as all of Laravel’s core services are bootstrapped via service providers”.(Laravel Official)
What is a service container?
Laravel official documentation says: “The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection.”(Laravel Official)
What is dependency injection in Laravel?
Dependency Injections pass the required dependency into an object externaly via constructor.
What are the Laravel Contracts?
Laravel’s Contracts are a set of interfaces that define the core services provided by the framework.
What are the Facades in Laravel?
In Laravel Facades are the classes that provide a “static” interface to classes that are available in the application’s service container. (Laravel Official)
How to enable query log in Laravel?
This is how you can enable query log in Laravel:
What is HTTP middleware?
As the name middleware is a common interface between request and response.
Middleware provide a convenient mechanism for filtering HTTP requests entering your application.
For example, Laravel includes a middleware that verifies the user of your application is authenticated.
Must Read: Codeigniter Interview Questions and answers
What is CSRF protection?
CSRF or Cross-Site Request Forgery is an attack that may lead unwanted and harmful action. We need to secure state changing stions from attacks. Laravel provide inbuilt CSRF protection.
What are query scopes?
Query scope is feature developed by Laravel where we can reuse similar queries.We don’t need to write similar types of queries again in the application.Once the scope has been defined, you may call the scope methods when querying the model.(Laravel Official)
What are the soft deletes and how do we do soft deletes?
Soft delete is a technique to flag a record so that it can be ignored from selection and invisible in view, but still available in table.We can implement it using Eloquent Model which supports Soft Delete feature.
What are Eloquent models?
Eloquent ORM- Object Run Mapper – used to implement Active Record Pattern while interecting with database. It can also be used outside of Laravel.
What is query builder in Laravel?
Laravel’s database query builder provides a convenient, fluent interface to creating and running database queries. It can be used to perform most database operations in your application and works on all supported database systems. (Laravel Official)
How can we run custom and raw query in Laravel?
Calling raw() functions of DB class:
$result_data = DB::raw(‘SELECT first_name,email_id from users’);