SlideShare une entreprise Scribd logo
1  sur  52
THE PHP FRAMEWORK FOR WEB
ARTISANS
1
By
Viral Solani
Tech Lead
Cygnet Infotech
Why Laravel ? Good Question !
• Inspired from battle tested frameworks (ROR , .Net)
• Built on top of symfony2 components
• Guides new developers to use good practices.
• Easy Learning Curve.
• Survived the PHP Framework War , now its one of the most used
frameworks.
• Expressive Syntax
• Utilizes the latest PHP features (Namespaces , Interface , PSR-
4 Auto loading , Ioc )
•Active and growing community that can provide quick support and answers
•Out of box Authentication , Localization etc.
• Well Documented (http://laravel.com/docs)
2
Modern Framework
• Routing
• Controllers
• Template Systems (Blade)
• Validation
• ORM (Eloquent)
• Authentication out of the box
• Logging
• Events
• Mail
➢ Queues
➢ Task Scheduling
➢ Elixier
➢ Localization
➢ Unit Testing (PHPunit)
➢ The list goes on….
3
What is Composer ?
•Composer is a tool for Dependency Management for PHP.
•Laravel utilizes Composer to manage its dependencies. So, before
using Laravel, make sure you have Composer installed on your
machine.
4
Your
Awesome
PHP
Project
(1) Read
composer.json
(2) Find Library form Packagist
(3) Download Library
(4) Library downloaded
on your project
How Composer works?
5
How to install Laravel ??
You can install Laravel by Three ways
- via laravel installer
- via composer
- clone from github
6
This will download laravel installer via composer
-composer global require "laravel/installer"
When installer added this simple command will create app
-laravel new <app name>
* Do not forget to add ~/.composer/vendor/bin to your PATH variable in
~/.bashrc
Via Laravel Installer
7
Via composer
- composer create-project laravel/laravel your-project-name
Get from GitHub
-https://github.com/laravel/laravel
-And then in the project dir run “composer install” to get all
needed packages
Other Options
8
Laravel Directory Structure
App
Bootstrap
Config
Database
Public
Resources
Storage
Tests
Vendor
.env
.env.example
.gitattribuites
.gitignore
Artisan
Composer.lock
Composer.json
Gulpfile.js
Package.json
Phpunit.xml
Readme.md
Server.php
9
Laravel Directory Structure : App
10
Routes
• Create routes at: app/Http/routes.php
• include() additional route definitions if needed
• Below Methods are available.
– Route::get();
– Route::post();
– Route::put();
– Route::patch();
– Route::delete();
– Route::any(); //all of above
11
Routes
app/Http/routes.php
Route::get('/', function(){ echo
‘Boom!’;
});
12
Routes
13
Controllers
Command : php artisan make:controller PhotoController
• The Artisan command will generate a controller file at
app/Http/Controllers/PhotoController.php.
• The controller will contain a method for each of the available
resource operations.
14
Resource Controller
php artisan make:controller PhotoController --resource
Route::resource('photos', 'PhotoController');
15
Views
• Views contain the HTML served by your application and separate
your controller / application logic from your presentation logic.
• Views are stored in the resources/views directory.
• Can be separated in subdirectories
• Can be both blade or simple php files
16
Blade Template Engine
• Laravel default template engine
• Files need to use .blade.php extension
• Driven by inheritance and sections
• all Blade views are compiled into plain PHP code and cached until
they are modified, meaning Blade adds essentially zero overhead to
your application.
• Extensible for adding new custom control structures (directives)
17
Defining a Layout
<!-- Stored in resources/views/layouts/app.blade.php -->
<html>
<head>
<title>App Name - @yield('title')</title>
</head>
<body>
@section('sidebar')
This is the master sidebar.
@show
<div class="container">
@yield('content')
</div>
</body>
</html>
18
Extending a Layout
<!-- Stored in resources/views/child.blade.php -->
@extends('layouts.app')
@section('title', 'Page Title')
@section('sidebar')
@parent
<p>This is appended to the master sidebar.</p>
@endsection
@section('content')
<p>This is my body content.</p>
@endsection
19
View System
• Returning a view from a route
Route::get('/', function()
{
return view('home.index');
//resources/views/home/index.blade.php
});
• Sending data to view
Route::get('/', function()
{
return view(‘home.index')->with('email', 'email@gmail.com');
});
20
Models
• Command to create model : php artisan make:model User
namespace App;
use IlluminateDatabaseEloquentModel;
class User extends Model
{
/**
* The table associated with the model.
*
* @var string
*/
protected $table = 'tablename';
}
21
Eloquent ORM
• Active Record
• Table – plural, snake_case class name
• Has a lot of useful methods
• is very flexible
• Has built in safe delete functionality
• Has built in Relationship functionality
• Timestamps
• Has option to define scopes
22
Eloquent ORM - Examples
$flights = AppFlight::where('active', 1)->orderBy('name', 'desc')->take(10) ->get();
// Retrieve a model by its primary key...
$flight = AppFlight::find(1);
// Retrieve the first model matching the query constraints...
$flight = AppFlight::where('active', 1)->first();
$flights = AppFlight::find([1, 2, 3]);
//Retrieving Aggregates
$count = AppFlight::where('active', 1)->count();
$max = AppFlight::where('active', 1)->max('price');
23
Query Builder
• The 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.
• Simple and Easy to Understand
• Used extensively by Eloquent ORM
24
Query Builder - Examples
//Retrieving All Rows From A Table
$users = DB::table('users')->get();
//Retrieving A Single Row / Column From A Table
$user = DB::table('users')->where('name', 'John')->first();
echo $user->name;
//Joins
$users = DB::table('users')
->leftJoin('posts', 'users.id', '=', 'posts.user_id')
->get();
25
Migrations & Seeders
• “Versioning” for your database , and fake data generator
• php artisan make:migration create_users_table
• php artisan make:migration add_votes_to_users_table
• php artisan make:seeder UsersTableSeeder
• php artisan db:seed
• php artisan db:seed --class=UsersTableSeeder
• php artisan migrate:refresh --seed26
Examples of Migration & Seeding
27
Middleware
• Route Filters
• Allows processing or filtering of requests entering the system
• Better , Faster , Stronger
• Defining Middleware : php artisan make:middleware Authenticate
• If you want a middleware to be run during every HTTP request to
your application, simply list the middleware class in the
$middleware property of your app/Http/Kernel.php class.
28
Middleware : Example
29
Middleware - Popular Uses :
• Auth
• ACL
• Session
• Caching
• Debug
• Logging
• Analytics
• Rate Limiting
30
Requests
• Command to Create Request php artisan make:request StoreBlogPostRequest
• Validators That are executed before hitting the action of the
Controller
• Basically Designed for Authorization and Form validation
31
Requests : Example
32
Service Providers
• Command to create Service Provider : php artisan make:provider
• Located at : app/Providers
• 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.
• But, what do we mean by "bootstrapped"? In general, we mean
registering things, including registering service container bindings,
event listeners, middleware, and even routes. Service providers are
the central place to configure your application.
33
Service Container
• The Laravel service container is a powerful tool for managing class
dependencies and performing dependency injection.
• Dependency injection is a fancy phrase that essentially means this:
class dependencies are "injected" into the class via the constructor
or, in some cases, "setter" methods.
• You need to bind all your service containers , it will be most probably
registered within service providers.
34
Service Container : Example
35
Facades
• Facade::doSomethingCool()
• Isn’t that a static method? - Well, no
• A «static» access to underlying service
• Look like static resources, but actually uses services underneath
• Classes are resolved behind the scene via Service Containers
• Laravel has a lot usefull usages of Facades like
– App::config()
– View::make()
– DB::table()
– Mail::send()
– Request::get()
– Session::get()
– Url::route()
– And much more…
36
Encryption
• Simplified encryption using OpenSSL and the AES-256-CBC cipher
• Available as Facade Crypt::encrypt() &Crypt::decrypt()
• Before using Laravel's encrypter, you should set the key option of
your config/app.phpconfiguration file to a 32 character, random
string. If this value is not properly set, all values encrypted by Laravel
will be insecure.
37
Artisan (CLI)
• Generates Skeleton Classes
• It runs migration and seeders
• It catches a lot of stuff (speed things up)
• It execute custom commands
• Command : Php artisan
38
Ecosystem
• Laravel
• Lumen
• Socialite
• Cashier
• Elixir
• Envoyer
• Spark
• Homestead
• Valet
• Forge
39
Lumen
• Micor-framework for Micro-services
• Sacrifices configurability for speed
• Easy upgrade to a full Laravel application
40
Socialite
• Integrates Social authentication functionality
• Almost for all popular platforms available
• http://socialiteproviders.github.io
41
Cashier
• Billing without the hassle
• Subscription logic included
• Easy to setup
42
Elixir
• Gulp simplified
• Compilation, concatenation, minifaction, auto-prefixing,…
• Support for
– Source Maps
– CoffeScript
– Browserify
– Babel
– …
43
Spark
• Billing
• Team management
• Invitations
• Registration
• 2-factor auth
• …
44
Homestead
• Comes with everything you need
– Ubuntu
– PHP 5.6 & 7
– Nginx
– MySQL & Postgres
– Node
– Memcached
– Redis
– ---
45
Forge
• Automates the process to setup a server
• You don’t need to learn how to set up one
• Saves you the effort of settings everything up
• Globally, saves you ridiculous amounts of time
46
Envoyer (!= Envoy)
• Zero downtime deployments
• Seamless rollbacks
• Cronjobs monitoring with heartbeats
• Deployment health status
• Deploy on multiple servers at once
47
Community
• Slack http://larachat.co/
• Forum https://laracasts.com/discuss
• Forum http://laravel.io/forum
• Twitter https://twitter.com/laravelphp
• GitHub https://github.com/laravel/laravel
48
Conference
• LaraconUS July 27-29, Kentucky USA
http://laracon.us/
• LaraconEU August 23-24, Amsterdam NL
http://laracon.eu
49
Learning
• Laravel Documentation https://laravel.com/
• Laracasts
https://laracasts.com/
50
CMS
• AsgardCMS https://asgardcms.com/
• OctoberCMS http://octobercms.com/
• Laravel 5 Boilerplate
https://github.com/rappasoft/laravel-5-boilerplate
51
52

Contenu connexe

Tendances

Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingChristopher Pecoraro
 
All Aboard for Laravel 5.1
All Aboard for Laravel 5.1All Aboard for Laravel 5.1
All Aboard for Laravel 5.1Jason McCreary
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel frameworkAhmad Fatoni
 
All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$Joe Ferguson
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New FeaturesJoe Ferguson
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 Joe Ferguson
 
Knowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkKnowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkBukhori Aqid
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel frameworkPhu Luong Trong
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Dilouar Hossain
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should knowPovilas Korop
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web ArtisansRaf Kewl
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Lorvent56
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Vikas Chauhan
 

Tendances (20)

Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
All Aboard for Laravel 5.1
All Aboard for Laravel 5.1All Aboard for Laravel 5.1
All Aboard for Laravel 5.1
 
Laravel 5.4
Laravel 5.4 Laravel 5.4
Laravel 5.4
 
Introduction to laravel framework
Introduction to laravel frameworkIntroduction to laravel framework
Introduction to laravel framework
 
All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$All the Laravel things: up and running to making $$
All the Laravel things: up and running to making $$
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New Features
 
Presentation laravel 5 4
Presentation laravel 5 4Presentation laravel 5 4
Presentation laravel 5 4
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
Knowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkKnowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP framework
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel framework
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should know
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
Laravel ppt
Laravel pptLaravel ppt
Laravel ppt
 

En vedette

Intro to Laravel PHP Framework
Intro to Laravel PHP FrameworkIntro to Laravel PHP Framework
Intro to Laravel PHP FrameworkBill Condo
 
Laravel Webcon 2015
Laravel Webcon 2015Laravel Webcon 2015
Laravel Webcon 2015Tim Bracken
 
Dependency Injection in Laravel
Dependency Injection in LaravelDependency Injection in Laravel
Dependency Injection in LaravelHAO-WEN ZHANG
 
MVC Seminar Presantation
MVC Seminar PresantationMVC Seminar Presantation
MVC Seminar PresantationAbhishek Yadav
 
Hash Functions, the MD5 Algorithm and the Future (SHA-3)
Hash Functions, the MD5 Algorithm and the Future (SHA-3)Hash Functions, the MD5 Algorithm and the Future (SHA-3)
Hash Functions, the MD5 Algorithm and the Future (SHA-3)Dylan Field
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In DepthKirk Bushell
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentationBhavin Shah
 

En vedette (10)

Intro to Laravel PHP Framework
Intro to Laravel PHP FrameworkIntro to Laravel PHP Framework
Intro to Laravel PHP Framework
 
Laravel Webcon 2015
Laravel Webcon 2015Laravel Webcon 2015
Laravel Webcon 2015
 
Dependency Injection in Laravel
Dependency Injection in LaravelDependency Injection in Laravel
Dependency Injection in Laravel
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
MVC Seminar Presantation
MVC Seminar PresantationMVC Seminar Presantation
MVC Seminar Presantation
 
Hash Functions, the MD5 Algorithm and the Future (SHA-3)
Hash Functions, the MD5 Algorithm and the Future (SHA-3)Hash Functions, the MD5 Algorithm and the Future (SHA-3)
Hash Functions, the MD5 Algorithm and the Future (SHA-3)
 
Hashing
HashingHashing
Hashing
 
Laravel 5 In Depth
Laravel 5 In DepthLaravel 5 In Depth
Laravel 5 In Depth
 
MVC ppt presentation
MVC ppt presentationMVC ppt presentation
MVC ppt presentation
 
Model View Controller (MVC)
Model View Controller (MVC)Model View Controller (MVC)
Model View Controller (MVC)
 

Similaire à Introduction to Laravel Framework (5.2)

Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxSaziaRahman
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravelConfiz
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileAmazon Web Services Japan
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with LaravelAbuzer Firdousi
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to LaravelEli Wheaton
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Nilesh Panchal
 
Lecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfLecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfShaimaaMohamedGalal
 
Ruby on Rails Penetration Testing
Ruby on Rails Penetration TestingRuby on Rails Penetration Testing
Ruby on Rails Penetration Testing3S Labs
 
Practices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPractices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPeter Hendriks
 
Ingesting hdfs intosolrusingsparktrimmed
Ingesting hdfs intosolrusingsparktrimmedIngesting hdfs intosolrusingsparktrimmed
Ingesting hdfs intosolrusingsparktrimmedwhoschek
 
What-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxWhat-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxAbhijeetKumar456867
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsDeepak Chandani
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxMichael Hackstein
 
Running Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on HadoopRunning Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on Hadoopclairvoyantllc
 
The Integration of Laravel with Swoole
The Integration of Laravel with SwooleThe Integration of Laravel with Swoole
The Integration of Laravel with SwooleAlbert Chen
 

Similaire à Introduction to Laravel Framework (5.2) (20)

Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & MobileIVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
IVS CTO Night And Day 2018 Winter - [re:Cap] Serverless & Mobile
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
Introduction to Monsoon PHP framework
Introduction to Monsoon PHP frameworkIntroduction to Monsoon PHP framework
Introduction to Monsoon PHP framework
 
Introduction to Laravel
Introduction to LaravelIntroduction to Laravel
Introduction to Laravel
 
Ember - introduction
Ember - introductionEmber - introduction
Ember - introduction
 
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
Ruby on-rails-101-presentation-slides-for-a-five-day-introductory-course-1194...
 
Lecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdfLecture11_LaravelGetStarted_SPring2023.pdf
Lecture11_LaravelGetStarted_SPring2023.pdf
 
Ruby on Rails Penetration Testing
Ruby on Rails Penetration TestingRuby on Rails Penetration Testing
Ruby on Rails Penetration Testing
 
Practices and Tools for Building Better APIs
Practices and Tools for Building Better APIsPractices and Tools for Building Better APIs
Practices and Tools for Building Better APIs
 
Solr Recipes
Solr RecipesSolr Recipes
Solr Recipes
 
Ingesting hdfs intosolrusingsparktrimmed
Ingesting hdfs intosolrusingsparktrimmedIngesting hdfs intosolrusingsparktrimmed
Ingesting hdfs intosolrusingsparktrimmed
 
What-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptxWhat-is-Laravel-23-August-2017.pptx
What-is-Laravel-23-August-2017.pptx
 
Creating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 ComponentsCreating your own framework on top of Symfony2 Components
Creating your own framework on top of Symfony2 Components
 
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
 
Rapid API Development ArangoDB Foxx
Rapid API Development ArangoDB FoxxRapid API Development ArangoDB Foxx
Rapid API Development ArangoDB Foxx
 
Rack
RackRack
Rack
 
Running Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on HadoopRunning Airflow Workflows as ETL Processes on Hadoop
Running Airflow Workflows as ETL Processes on Hadoop
 
The Integration of Laravel with Swoole
The Integration of Laravel with SwooleThe Integration of Laravel with Swoole
The Integration of Laravel with Swoole
 

Dernier

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxKatpro Technologies
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure servicePooja Nehwal
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountPuma Security, LLC
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machinePadma Pradeep
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking MenDelhi Call girls
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 

Dernier (20)

Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptxFactors to Consider When Choosing Accounts Payable Services Providers.pptx
Factors to Consider When Choosing Accounts Payable Services Providers.pptx
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure serviceWhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
WhatsApp 9892124323 ✓Call Girls In Kalyan ( Mumbai ) secure service
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Breaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path MountBreaking the Kubernetes Kill Chain: Host Path Mount
Breaking the Kubernetes Kill Chain: Host Path Mount
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
Neo4j - How KGs are shaping the future of Generative AI at AWS Summit London ...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
Install Stable Diffusion in windows machine
Install Stable Diffusion in windows machineInstall Stable Diffusion in windows machine
Install Stable Diffusion in windows machine
 
08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men08448380779 Call Girls In Civil Lines Women Seeking Men
08448380779 Call Girls In Civil Lines Women Seeking Men
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 

Introduction to Laravel Framework (5.2)

  • 1. THE PHP FRAMEWORK FOR WEB ARTISANS 1 By Viral Solani Tech Lead Cygnet Infotech
  • 2. Why Laravel ? Good Question ! • Inspired from battle tested frameworks (ROR , .Net) • Built on top of symfony2 components • Guides new developers to use good practices. • Easy Learning Curve. • Survived the PHP Framework War , now its one of the most used frameworks. • Expressive Syntax • Utilizes the latest PHP features (Namespaces , Interface , PSR- 4 Auto loading , Ioc ) •Active and growing community that can provide quick support and answers •Out of box Authentication , Localization etc. • Well Documented (http://laravel.com/docs) 2
  • 3. Modern Framework • Routing • Controllers • Template Systems (Blade) • Validation • ORM (Eloquent) • Authentication out of the box • Logging • Events • Mail ➢ Queues ➢ Task Scheduling ➢ Elixier ➢ Localization ➢ Unit Testing (PHPunit) ➢ The list goes on…. 3
  • 4. What is Composer ? •Composer is a tool for Dependency Management for PHP. •Laravel utilizes Composer to manage its dependencies. So, before using Laravel, make sure you have Composer installed on your machine. 4
  • 5. Your Awesome PHP Project (1) Read composer.json (2) Find Library form Packagist (3) Download Library (4) Library downloaded on your project How Composer works? 5
  • 6. How to install Laravel ?? You can install Laravel by Three ways - via laravel installer - via composer - clone from github 6
  • 7. This will download laravel installer via composer -composer global require "laravel/installer" When installer added this simple command will create app -laravel new <app name> * Do not forget to add ~/.composer/vendor/bin to your PATH variable in ~/.bashrc Via Laravel Installer 7
  • 8. Via composer - composer create-project laravel/laravel your-project-name Get from GitHub -https://github.com/laravel/laravel -And then in the project dir run “composer install” to get all needed packages Other Options 8
  • 11. Routes • Create routes at: app/Http/routes.php • include() additional route definitions if needed • Below Methods are available. – Route::get(); – Route::post(); – Route::put(); – Route::patch(); – Route::delete(); – Route::any(); //all of above 11
  • 14. Controllers Command : php artisan make:controller PhotoController • The Artisan command will generate a controller file at app/Http/Controllers/PhotoController.php. • The controller will contain a method for each of the available resource operations. 14
  • 15. Resource Controller php artisan make:controller PhotoController --resource Route::resource('photos', 'PhotoController'); 15
  • 16. Views • Views contain the HTML served by your application and separate your controller / application logic from your presentation logic. • Views are stored in the resources/views directory. • Can be separated in subdirectories • Can be both blade or simple php files 16
  • 17. Blade Template Engine • Laravel default template engine • Files need to use .blade.php extension • Driven by inheritance and sections • all Blade views are compiled into plain PHP code and cached until they are modified, meaning Blade adds essentially zero overhead to your application. • Extensible for adding new custom control structures (directives) 17
  • 18. Defining a Layout <!-- Stored in resources/views/layouts/app.blade.php --> <html> <head> <title>App Name - @yield('title')</title> </head> <body> @section('sidebar') This is the master sidebar. @show <div class="container"> @yield('content') </div> </body> </html> 18
  • 19. Extending a Layout <!-- Stored in resources/views/child.blade.php --> @extends('layouts.app') @section('title', 'Page Title') @section('sidebar') @parent <p>This is appended to the master sidebar.</p> @endsection @section('content') <p>This is my body content.</p> @endsection 19
  • 20. View System • Returning a view from a route Route::get('/', function() { return view('home.index'); //resources/views/home/index.blade.php }); • Sending data to view Route::get('/', function() { return view(‘home.index')->with('email', 'email@gmail.com'); }); 20
  • 21. Models • Command to create model : php artisan make:model User namespace App; use IlluminateDatabaseEloquentModel; class User extends Model { /** * The table associated with the model. * * @var string */ protected $table = 'tablename'; } 21
  • 22. Eloquent ORM • Active Record • Table – plural, snake_case class name • Has a lot of useful methods • is very flexible • Has built in safe delete functionality • Has built in Relationship functionality • Timestamps • Has option to define scopes 22
  • 23. Eloquent ORM - Examples $flights = AppFlight::where('active', 1)->orderBy('name', 'desc')->take(10) ->get(); // Retrieve a model by its primary key... $flight = AppFlight::find(1); // Retrieve the first model matching the query constraints... $flight = AppFlight::where('active', 1)->first(); $flights = AppFlight::find([1, 2, 3]); //Retrieving Aggregates $count = AppFlight::where('active', 1)->count(); $max = AppFlight::where('active', 1)->max('price'); 23
  • 24. Query Builder • The 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. • Simple and Easy to Understand • Used extensively by Eloquent ORM 24
  • 25. Query Builder - Examples //Retrieving All Rows From A Table $users = DB::table('users')->get(); //Retrieving A Single Row / Column From A Table $user = DB::table('users')->where('name', 'John')->first(); echo $user->name; //Joins $users = DB::table('users') ->leftJoin('posts', 'users.id', '=', 'posts.user_id') ->get(); 25
  • 26. Migrations & Seeders • “Versioning” for your database , and fake data generator • php artisan make:migration create_users_table • php artisan make:migration add_votes_to_users_table • php artisan make:seeder UsersTableSeeder • php artisan db:seed • php artisan db:seed --class=UsersTableSeeder • php artisan migrate:refresh --seed26
  • 27. Examples of Migration & Seeding 27
  • 28. Middleware • Route Filters • Allows processing or filtering of requests entering the system • Better , Faster , Stronger • Defining Middleware : php artisan make:middleware Authenticate • If you want a middleware to be run during every HTTP request to your application, simply list the middleware class in the $middleware property of your app/Http/Kernel.php class. 28
  • 30. Middleware - Popular Uses : • Auth • ACL • Session • Caching • Debug • Logging • Analytics • Rate Limiting 30
  • 31. Requests • Command to Create Request php artisan make:request StoreBlogPostRequest • Validators That are executed before hitting the action of the Controller • Basically Designed for Authorization and Form validation 31
  • 33. Service Providers • Command to create Service Provider : php artisan make:provider • Located at : app/Providers • 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. • But, what do we mean by "bootstrapped"? In general, we mean registering things, including registering service container bindings, event listeners, middleware, and even routes. Service providers are the central place to configure your application. 33
  • 34. Service Container • The Laravel service container is a powerful tool for managing class dependencies and performing dependency injection. • Dependency injection is a fancy phrase that essentially means this: class dependencies are "injected" into the class via the constructor or, in some cases, "setter" methods. • You need to bind all your service containers , it will be most probably registered within service providers. 34
  • 35. Service Container : Example 35
  • 36. Facades • Facade::doSomethingCool() • Isn’t that a static method? - Well, no • A «static» access to underlying service • Look like static resources, but actually uses services underneath • Classes are resolved behind the scene via Service Containers • Laravel has a lot usefull usages of Facades like – App::config() – View::make() – DB::table() – Mail::send() – Request::get() – Session::get() – Url::route() – And much more… 36
  • 37. Encryption • Simplified encryption using OpenSSL and the AES-256-CBC cipher • Available as Facade Crypt::encrypt() &Crypt::decrypt() • Before using Laravel's encrypter, you should set the key option of your config/app.phpconfiguration file to a 32 character, random string. If this value is not properly set, all values encrypted by Laravel will be insecure. 37
  • 38. Artisan (CLI) • Generates Skeleton Classes • It runs migration and seeders • It catches a lot of stuff (speed things up) • It execute custom commands • Command : Php artisan 38
  • 39. Ecosystem • Laravel • Lumen • Socialite • Cashier • Elixir • Envoyer • Spark • Homestead • Valet • Forge 39
  • 40. Lumen • Micor-framework for Micro-services • Sacrifices configurability for speed • Easy upgrade to a full Laravel application 40
  • 41. Socialite • Integrates Social authentication functionality • Almost for all popular platforms available • http://socialiteproviders.github.io 41
  • 42. Cashier • Billing without the hassle • Subscription logic included • Easy to setup 42
  • 43. Elixir • Gulp simplified • Compilation, concatenation, minifaction, auto-prefixing,… • Support for – Source Maps – CoffeScript – Browserify – Babel – … 43
  • 44. Spark • Billing • Team management • Invitations • Registration • 2-factor auth • … 44
  • 45. Homestead • Comes with everything you need – Ubuntu – PHP 5.6 & 7 – Nginx – MySQL & Postgres – Node – Memcached – Redis – --- 45
  • 46. Forge • Automates the process to setup a server • You don’t need to learn how to set up one • Saves you the effort of settings everything up • Globally, saves you ridiculous amounts of time 46
  • 47. Envoyer (!= Envoy) • Zero downtime deployments • Seamless rollbacks • Cronjobs monitoring with heartbeats • Deployment health status • Deploy on multiple servers at once 47
  • 48. Community • Slack http://larachat.co/ • Forum https://laracasts.com/discuss • Forum http://laravel.io/forum • Twitter https://twitter.com/laravelphp • GitHub https://github.com/laravel/laravel 48
  • 49. Conference • LaraconUS July 27-29, Kentucky USA http://laracon.us/ • LaraconEU August 23-24, Amsterdam NL http://laracon.eu 49
  • 50. Learning • Laravel Documentation https://laravel.com/ • Laracasts https://laracasts.com/ 50
  • 51. CMS • AsgardCMS https://asgardcms.com/ • OctoberCMS http://octobercms.com/ • Laravel 5 Boilerplate https://github.com/rappasoft/laravel-5-boilerplate 51
  • 52. 52