SlideShare ist ein Scribd-Unternehmen logo
1 von 38
Downloaden Sie, um offline zu lesen
Introduction to Laravel 4
Benson Liang
What will be discussed


Introduction



Installation



The MVC Layers



Authentication



IoC Container



Facade



Service Provider
Introduction


The Creator



Objectives of Laravel



The Base



Closures



The Syntactic Sugar
Introduction – The Creator

Taylor Otwell
.NET Developer
Introduction – Objectives of Laravel


Get started on a project FAST



Fun to develop with



Promote S.O.L.I.D design patterns


Singe Responsibility Principle (SRP)



Open/Closed Principle (OCP)



Liskov Substitution Principle (LSP)



Interface Segregation Principle (ISP)



Dependency Inversion Principle (DIP)
Introduction – The Base


Composer friendly



Symfony components



Swiftmailer



Monolog



... and many more
Introduction - Closures


Introduced in PHP 5.3



Anonymous functions



Useful for specifying callbacks
Route::get(
'/login',
'AuthController@showLoginForm'
);
Route::get('/login', function() {
return View::make('auth.loginForm');
});
Introduction – The Syntactic Sugar


Easy to understand



Expressiveness and elegance
Auth::attempt()
Input::get()
Cookie::make()
Event::subscribe()
Installation

composer create-project laravel/laravel /web/laraveltest --no-dev --prefer-dist
The MVC Layers
●

Eloquent ORM

●

Blade Engine

●

Controller
The MVC Layers – Eloquent ORM
●

Active record style

●

Easy to use

class Book extends Eloquent
{
protected $table = 'book';
protected $primaryKey = 'book_id';
public $timestamps = false;
}
The MVC Layers – Eloquent ORM
●

Some examples of queries:
Book::all();
Book::find(1);
Book::where('name', '=', 'Michael Cheng');

●

Insert / Update
$b = new Book();
$b->title = 'Laravel Basics';
$b->description = 'A very nice book';
$b->save();
$b = Book::find(2);
$b->title = 'Laravel Advanced';
$b->save();
The MVC Layers – Eloquent ORM
●

Relationship mapping
public function author()
{
return $this->belongsTo('Author', 'author_id');
}
The MVC Layers – Eloquent ORM
●

Supports soft delete
protected $softDelete = true;
// Automatically excludes soft deleted rows
Book::all();
// Include soft deleted rows
Book::withTrashed()->get();
// Include only soft deleted rows
Book::onlyTrashed()->get();
// Undo the soft delete
$b = Book::withTrashed()->where('book_id, '=', 1);
$b->restore();
The MVC Layers – Eloquent ORM
●

Supports query scope
public function scopePopular($query)
{
return $query->where('rating', '>', '4');
}
Book::popular()->get();
The MVC Layers – Eloquent ORM
●

Supports accessors and mutators
// Accessor
public function getGenderAttribute($value)
{
return ($value == 'm') ? 'Male' : 'Female';
}
// Mutator
public function setNameAttribute($value)
{
$this->attributes['name'] = strtolower($value);
}
The MVC Layers – Blade Engine
●

Stock templating engine for Laravel

●

Supports template inheritance and sections
<html>
<head>
<title>@yield('page_title')</title>
@yield('css')
@yield('javascript')
</head>
<body>
Some text
@yield('content')
</body>
</html>
The MVC Layers – Blade Engine
@extends('layout')
@section('page_title', 'Login Page')
@section('css')
<link rel="stylesheet" type="text/css" href="mystyle.css" />
@endsection
@section('javascript')
<script type='text/javascript' src='jquery.js'></script>
@endsection
@section('content')
This is the content for a particular page.
@endsection
The MVC Layers – Blade Engine
●

Some control structures
@if (.....)
....
@elseif ....
@else ....
@endif

@unless (....)
....
@endunless
The MVC Layers – Blade Engine
@for (....)
....
@endfor

@while (....)
....
@endwhile
@foreach (....)
....
@endforeach
The MVC Layers – Blade Engine
●

Alternate way to echo variable values
My name is <?php echo $user->name ?>
My name is {{ $user->name }}
The MVC Layers - Controller
●

Basic controller
// The controller itself
class AuthController extends BaseController
{
public function showLoginForm()
{
return View::make('auth.loginForm');
}
}
// Routing file
Route::get('/auth', 'AuthController@showLoginForm')
The MVC Layers - Controller
●

RESTful controller
// The controller itself
class BookController extends BaseController
{
public function getShowAll()
{
// ..............
}
public function postAdd()
{
// ..............
}
}
// Routing file
Route::controller('/books', 'BookController');
The MVC Layers - Controller


Resource controller
–

Generated using Artisan CLI

–

Allows easy RESTful implementation
The MVC Layers - Controller


Resource controller


Paths and route names are generated automatically
Verb

Path

Action

Route Name

GET

/resource

index

resource.index

GET

/resource/create

create

resource.create

POST

/resource/

store

resource.store

GET

/resource/{id}

show

resource.show

GET

/resource/{id}/edit edit

resource.edit

PUT / PATCH

/resource/{id}

update

resource.update

DELETE

/resource/{id}

destroy

resource.destroy
The MVC Layers
●

Simple demo
Authentication
●



Allows easy implementation of user authentication for your
application
Supports multiple types of authentication


HTTP Basic



Application level
Authentication – Application Level
●

Many convenience methods
// Attempt to login
Auth::attempt(array('email' => $email, 'password' => $pwd))
// Check if the current user is logged in
Auth::check();
// Access the logged in user
$name = Auth::user()->name;
// Manually login a user with its ID
Auth::loginUsingId(1);
// Log the user out
Auth::logout();
Authentication – Application Level


Uses Bcrypt as the default hashing algorithm, with a
default workload of 8



Workload can be changed freely



Algorithm itself can be changed by framework extension
// Workload 8 by default
$hash = Hash::make('password');
// Change workload
$hash = Hash::make('password', array('rounds' => 12));
IoC Container








For managing class dependencies
Promotes inversion of control by injecting dependencies at
runtime
Promotes greater flexibility by allowing dependency
implementations to be swapped easily
2 ways for resolving types:


Closure



Automatic Resolution
IoC Container


Closure
App::bind('user_manager', function($app)
{
return new UserRepository();
});
//
//
//
//

.........
.........
.........
.........

$um = App::make('user_manager');
IoC Container


Automatic Resolution
class UserManager
{
private $repo;
public function __construct(UserRepository $repo)
{
$this->repo = $repo;
}
}
$u = App::make('UserManager');
IoC Container


Automatic Resolution
class UserManager
{
private $repo;
public function __construct(UserRepositoryInterface $repo)
{
$this->repo = $repo;
}
}
// Interface resolution
App::bind('UserRepositoryInterface', 'DbUserRepository');
// Now we can use the IoC container to resolve the dependencies
$u = App::make('UserManager');
Facade
●

●

Provides a static-like syntax to access objects and their
methods in the IoC container
These are facades in action, and they are NOT static
method calls:
Auth::attempt()
Input::get()
Cookie::make()
Event::subscribe()
Facade
●

How does it work?


An object is registered into the IoC container



A facade is created to reference that object



An alias is defined to use the facade without importing
its namespace
Service Provider
●

●

A great way to add reusable components into your
application
Custom authentication driver, database driver, support
modules etc etc etc...
Service Provider
class MongoDBServiceProvider extends ServiceProvider
{
public function register()
{
$this->app->bind('mongodb', function() {
return new MongoDbManager();
});
}
}
// Register the service provider
App::register('MongoDBServiceProvider');
// Now you can use the Mongo DB manager
$mongodb = App::make('mongodb');
$mongodb->connect(....);
$mongodb->add(....);
Tips For Learning Laravel
●

●

Documentation is your best friend
Read the API to discover features not mentioned in the
documentation

●

Get used to closures

●

Learn the IoC container and service provider (MUST)

Weitere ähnliche Inhalte

Was ist angesagt?

Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.SWAAM Tech
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Viral Solani
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should knowPovilas Korop
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5Bukhori Aqid
 
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
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New FeaturesJoe Ferguson
 
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
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingChristopher Pecoraro
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentationToufiq Mahmud
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravelConfiz
 
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
 
All Aboard for Laravel 5.1
All Aboard for Laravel 5.1All Aboard for Laravel 5.1
All Aboard for Laravel 5.1Jason McCreary
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloudphp[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the CloudJoe Ferguson
 

Was ist angesagt? (20)

Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.
 
Intro to Laravel
Intro to LaravelIntro to Laravel
Intro to Laravel
 
Presentation laravel 5 4
Presentation laravel 5 4Presentation laravel 5 4
Presentation laravel 5 4
 
Laravel 5.4
Laravel 5.4 Laravel 5.4
Laravel 5.4
 
Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)Introduction to Laravel Framework (5.2)
Introduction to Laravel Framework (5.2)
 
Why Laravel?
Why Laravel?Why Laravel?
Why Laravel?
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should know
 
Getting to know Laravel 5
Getting to know Laravel 5Getting to know Laravel 5
Getting to know Laravel 5
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New Features
 
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 $$
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Laravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routingLaravel 5 Annotations: RESTful API routing
Laravel 5 Annotations: RESTful API routing
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
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
 
All Aboard for Laravel 5.1
All Aboard for Laravel 5.1All Aboard for Laravel 5.1
All Aboard for Laravel 5.1
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloudphp[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
 

Ähnlich wie Intro to Laravel 4

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
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's CodeWildan Maulana
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Tuna Tore
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892Tuna Tore
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For ManagersAgileThought
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js frameworkBen Lin
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applicationshchen1
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress DevelopmentAdam Tomat
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsMike Subelsky
 
Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 3camp
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitMike Pfaff
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenchesLukas Smith
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSGunnar Hillert
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSAntonio Peric-Mazar
 
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
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...Fabio Franzini
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsRan Mizrahi
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)Igor Bronovskyy
 

Ähnlich wie Intro to Laravel 4 (20)

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...
 
Exploring Symfony's Code
Exploring Symfony's CodeExploring Symfony's Code
Exploring Symfony's Code
 
Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5Java Spring MVC Framework with AngularJS by Google and HTML5
Java Spring MVC Framework with AngularJS by Google and HTML5
 
springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892springmvc-150923124312-lva1-app6892
springmvc-150923124312-lva1-app6892
 
Patterns Are Good For Managers
Patterns Are Good For ManagersPatterns Are Good For Managers
Patterns Are Good For Managers
 
How and why i roll my own node.js framework
How and why i roll my own node.js frameworkHow and why i roll my own node.js framework
How and why i roll my own node.js framework
 
Codegnitorppt
CodegnitorpptCodegnitorppt
Codegnitorppt
 
Developing Java Web Applications
Developing Java Web ApplicationsDeveloping Java Web Applications
Developing Java Web Applications
 
[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development[Bristol WordPress] Supercharging WordPress Development
[Bristol WordPress] Supercharging WordPress Development
 
Symfony2 and AngularJS
Symfony2 and AngularJSSymfony2 and AngularJS
Symfony2 and AngularJS
 
SproutCore and the Future of Web Apps
SproutCore and the Future of Web AppsSproutCore and the Future of Web Apps
SproutCore and the Future of Web Apps
 
Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2 Osiąganie mądrej architektury z Symfony2
Osiąganie mądrej architektury z Symfony2
 
SCR Annotations for Fun and Profit
SCR Annotations for Fun and ProfitSCR Annotations for Fun and Profit
SCR Annotations for Fun and Profit
 
Symfony2 - from the trenches
Symfony2 - from the trenchesSymfony2 - from the trenches
Symfony2 - from the trenches
 
Modular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJSModular Test-driven SPAs with Spring and AngularJS
Modular Test-driven SPAs with Spring and AngularJS
 
Building Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJSBuilding Single Page Application (SPA) with Symfony2 and AngularJS
Building Single Page Application (SPA) with Symfony2 and AngularJS
 
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
 
WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...WebNet Conference 2012 - Designing complex applications using html5 and knock...
WebNet Conference 2012 - Designing complex applications using html5 and knock...
 
How AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design PatternsHow AngularJS Embraced Traditional Design Patterns
How AngularJS Embraced Traditional Design Patterns
 
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
09 - express nodes on the right angle - vitaliy basyuk - it event 2013 (5)
 

Kürzlich hochgeladen

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Mark Simos
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESmohitsingh558521
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 

Kürzlich hochgeladen (20)

Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptx
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
Tampa BSides - Chef's Tour of Microsoft Security Adoption Framework (SAF)
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICESSALESFORCE EDUCATION CLOUD | FEXLE SERVICES
SALESFORCE EDUCATION CLOUD | FEXLE SERVICES
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 

Intro to Laravel 4

  • 1. Introduction to Laravel 4 Benson Liang
  • 2. What will be discussed  Introduction  Installation  The MVC Layers  Authentication  IoC Container  Facade  Service Provider
  • 3. Introduction  The Creator  Objectives of Laravel  The Base  Closures  The Syntactic Sugar
  • 4. Introduction – The Creator Taylor Otwell .NET Developer
  • 5. Introduction – Objectives of Laravel  Get started on a project FAST  Fun to develop with  Promote S.O.L.I.D design patterns  Singe Responsibility Principle (SRP)  Open/Closed Principle (OCP)  Liskov Substitution Principle (LSP)  Interface Segregation Principle (ISP)  Dependency Inversion Principle (DIP)
  • 6. Introduction – The Base  Composer friendly  Symfony components  Swiftmailer  Monolog  ... and many more
  • 7. Introduction - Closures  Introduced in PHP 5.3  Anonymous functions  Useful for specifying callbacks Route::get( '/login', 'AuthController@showLoginForm' ); Route::get('/login', function() { return View::make('auth.loginForm'); });
  • 8. Introduction – The Syntactic Sugar  Easy to understand  Expressiveness and elegance Auth::attempt() Input::get() Cookie::make() Event::subscribe()
  • 9. Installation composer create-project laravel/laravel /web/laraveltest --no-dev --prefer-dist
  • 10. The MVC Layers ● Eloquent ORM ● Blade Engine ● Controller
  • 11. The MVC Layers – Eloquent ORM ● Active record style ● Easy to use class Book extends Eloquent { protected $table = 'book'; protected $primaryKey = 'book_id'; public $timestamps = false; }
  • 12. The MVC Layers – Eloquent ORM ● Some examples of queries: Book::all(); Book::find(1); Book::where('name', '=', 'Michael Cheng'); ● Insert / Update $b = new Book(); $b->title = 'Laravel Basics'; $b->description = 'A very nice book'; $b->save(); $b = Book::find(2); $b->title = 'Laravel Advanced'; $b->save();
  • 13. The MVC Layers – Eloquent ORM ● Relationship mapping public function author() { return $this->belongsTo('Author', 'author_id'); }
  • 14. The MVC Layers – Eloquent ORM ● Supports soft delete protected $softDelete = true; // Automatically excludes soft deleted rows Book::all(); // Include soft deleted rows Book::withTrashed()->get(); // Include only soft deleted rows Book::onlyTrashed()->get(); // Undo the soft delete $b = Book::withTrashed()->where('book_id, '=', 1); $b->restore();
  • 15. The MVC Layers – Eloquent ORM ● Supports query scope public function scopePopular($query) { return $query->where('rating', '>', '4'); } Book::popular()->get();
  • 16. The MVC Layers – Eloquent ORM ● Supports accessors and mutators // Accessor public function getGenderAttribute($value) { return ($value == 'm') ? 'Male' : 'Female'; } // Mutator public function setNameAttribute($value) { $this->attributes['name'] = strtolower($value); }
  • 17. The MVC Layers – Blade Engine ● Stock templating engine for Laravel ● Supports template inheritance and sections <html> <head> <title>@yield('page_title')</title> @yield('css') @yield('javascript') </head> <body> Some text @yield('content') </body> </html>
  • 18. The MVC Layers – Blade Engine @extends('layout') @section('page_title', 'Login Page') @section('css') <link rel="stylesheet" type="text/css" href="mystyle.css" /> @endsection @section('javascript') <script type='text/javascript' src='jquery.js'></script> @endsection @section('content') This is the content for a particular page. @endsection
  • 19. The MVC Layers – Blade Engine ● Some control structures @if (.....) .... @elseif .... @else .... @endif @unless (....) .... @endunless
  • 20. The MVC Layers – Blade Engine @for (....) .... @endfor @while (....) .... @endwhile @foreach (....) .... @endforeach
  • 21. The MVC Layers – Blade Engine ● Alternate way to echo variable values My name is <?php echo $user->name ?> My name is {{ $user->name }}
  • 22. The MVC Layers - Controller ● Basic controller // The controller itself class AuthController extends BaseController { public function showLoginForm() { return View::make('auth.loginForm'); } } // Routing file Route::get('/auth', 'AuthController@showLoginForm')
  • 23. The MVC Layers - Controller ● RESTful controller // The controller itself class BookController extends BaseController { public function getShowAll() { // .............. } public function postAdd() { // .............. } } // Routing file Route::controller('/books', 'BookController');
  • 24. The MVC Layers - Controller  Resource controller – Generated using Artisan CLI – Allows easy RESTful implementation
  • 25. The MVC Layers - Controller  Resource controller  Paths and route names are generated automatically Verb Path Action Route Name GET /resource index resource.index GET /resource/create create resource.create POST /resource/ store resource.store GET /resource/{id} show resource.show GET /resource/{id}/edit edit resource.edit PUT / PATCH /resource/{id} update resource.update DELETE /resource/{id} destroy resource.destroy
  • 27. Authentication ●  Allows easy implementation of user authentication for your application Supports multiple types of authentication  HTTP Basic  Application level
  • 28. Authentication – Application Level ● Many convenience methods // Attempt to login Auth::attempt(array('email' => $email, 'password' => $pwd)) // Check if the current user is logged in Auth::check(); // Access the logged in user $name = Auth::user()->name; // Manually login a user with its ID Auth::loginUsingId(1); // Log the user out Auth::logout();
  • 29. Authentication – Application Level  Uses Bcrypt as the default hashing algorithm, with a default workload of 8  Workload can be changed freely  Algorithm itself can be changed by framework extension // Workload 8 by default $hash = Hash::make('password'); // Change workload $hash = Hash::make('password', array('rounds' => 12));
  • 30. IoC Container     For managing class dependencies Promotes inversion of control by injecting dependencies at runtime Promotes greater flexibility by allowing dependency implementations to be swapped easily 2 ways for resolving types:  Closure  Automatic Resolution
  • 31. IoC Container  Closure App::bind('user_manager', function($app) { return new UserRepository(); }); // // // // ......... ......... ......... ......... $um = App::make('user_manager');
  • 32. IoC Container  Automatic Resolution class UserManager { private $repo; public function __construct(UserRepository $repo) { $this->repo = $repo; } } $u = App::make('UserManager');
  • 33. IoC Container  Automatic Resolution class UserManager { private $repo; public function __construct(UserRepositoryInterface $repo) { $this->repo = $repo; } } // Interface resolution App::bind('UserRepositoryInterface', 'DbUserRepository'); // Now we can use the IoC container to resolve the dependencies $u = App::make('UserManager');
  • 34. Facade ● ● Provides a static-like syntax to access objects and their methods in the IoC container These are facades in action, and they are NOT static method calls: Auth::attempt() Input::get() Cookie::make() Event::subscribe()
  • 35. Facade ● How does it work?  An object is registered into the IoC container  A facade is created to reference that object  An alias is defined to use the facade without importing its namespace
  • 36. Service Provider ● ● A great way to add reusable components into your application Custom authentication driver, database driver, support modules etc etc etc...
  • 37. Service Provider class MongoDBServiceProvider extends ServiceProvider { public function register() { $this->app->bind('mongodb', function() { return new MongoDbManager(); }); } } // Register the service provider App::register('MongoDBServiceProvider'); // Now you can use the Mongo DB manager $mongodb = App::make('mongodb'); $mongodb->connect(....); $mongodb->add(....);
  • 38. Tips For Learning Laravel ● ● Documentation is your best friend Read the API to discover features not mentioned in the documentation ● Get used to closures ● Learn the IoC container and service provider (MUST)