SlideShare a Scribd company logo
Laravel Meetup
Introduction
LARAVEL FRAMEWORK
Whisnu Sucitanuary
Laravel Framework
Introduction
• 10:00 – 12:00
• 12:00 – 13:00
• 13:00 – 15:00
• Introduction
• Installation
• Create Project
• Laravel Project Structure
• Route and Filtering
• MVC
• Migration and Seeder
• Break
• Walkthrough
Outline
I Simply found on their website :D
RESTful Routing
Command Your Data
Beautiful Templating
Ready For Tomorrow
Proven Foundation
Composer Powered
Great Community
Red, Green, Refactor
TAYLOR OTWELL
He’s
The
Man
Laravel About
• Laravel is a web application framework with expressive, elegant syntax.
• A modern PHP 5.3 MVC Framework
• Released in July 2011
• Easy to understand for both code and documentation (fun to develop with)
• Composer-based and friendly
• Promote S.O.L.I.D design pattern
• Supported by a thriving community
• Member of PSR project
• Licensed MIT
Some Laravel Fancy Features
• Flexible Routing
• Dependency Injection / IoC Container
• Event Binding
• Cache Drivers
• Queue Drivers
• Authentication Drivers
• Powerfull ActiveRecord ORM
• Command-line utility
• Testing Helpers
• ...
THE PHILOSOPHY
“Any time that I have to do something that is a pain...
it puts a seed in my head to work it into Laravel”
• Reducing developmental pain points
• Simple to use / expressive API
• Give the developer the control over their architecture
• Grows with the developer
Laravel Become Mainstream
• 294 Contributors To Laravel 4.x
• 7.000 Closed Issues
• Most Starred PHP Project on Github
• Most Watched PHP Project on Github
• 1.2 Millions+ Composer Installs
Source : Laracon 2014 Keynote – Taylor Otwell
Installation
• Install Composer
• Install Laravel
• Laravel Installer using composer
composer global require "laravel/installer=~1.1"
composer create-project laravel/laravel laravel-demo
• Git clone
https://github.com/laravel/laravel
• Download
https://github.com/laravel/laravel/archive/master.zip
PHP >= 5.4
MCrypt PHP Extension
Simplicity From Download To Deploy
Laravel Homestead
Laravel Homestead
• Official Laravel Vagrant Box (http://www.vagrantup.com)
• Pre-Package for Super Fast Installation
• Dead Simple Configuration File
• All Your Project On a Single Box
• It’s Heavenly :D
Laravel ForgeServers for Artisans | forge.laravel.com
Laravel Forge
• Instant PHP Platforms
• Cloud of your choice
Expresiveness
$articles = Article::where('author','=','otwell')
->orderBy('date','desc')
->skip(5)
->take(5)
->get();
Auth:check();
Cache::forever(‘the_man’,’otwell’);
Redirect::to('user/login')->with('message', 'Login Failed');
Powerfull Command line Tool
• Based off symfony’s console
component
• Allow a number of application
management task to be run
from the CLI (code generation,
DB process,etc)
• Easly customizable-write your
own
Interactive shell (tinker)
Laravel Project Structure
> composer update
ROUTING & FILTERING
Routing
• Implicit Routing
• Routing to Controller
• Routing to Resources (REST)
Implicit Routing
Route::get('news',function(){
return '<p>News Page</p>';
});
Route::get('news/{id}',function($id){
return 'News with id '.$id;
})->where('id','[0-9]+')
Routing to Controller
Route::controller('news','NewsController');
Route::controller('login','LoginController');
Route::controller('admin','AdminController');
class NewsController{
public function getIndex(){...}
public function getArticles(){...}
public function postComment(){...}
public function getAuthorProfile(){...} //news/author-profile
}
Route to Resources (REST)
Route::resource('news','NewsController');
class NewsController{
public function index(){...}
public function create(){...}
public function store(){...}
public function show(){...}
public function edit(){...}
public function update(){...}
public function destroy(){...}
}
Route Filtering
Route::filter('old', function()
{
if (Input::get('age') < 200)
{
return Redirect::to('home');
}
});
Route::get('user', array('before' => 'old', function()
{
return 'You are over 200 years old!';
}));
• Easy to understand
• Expressiveness and Elegance
The Syntactic Sugar
Auth::check();
Input::get();
Cookie::make();
Event::subscribe();
Pesan::kirim(); // your own facade example
Static Method !?
App:bind('mailer',function(){
return new Mailer();
});
Route::filter('auth',function(){
if(Auth::guest())
return Redirect::action('AuthController@getLogin');
});
Route::model('user','User');
Facades
Enable you to hide complex interfacec behind a simple one.
What Really Happening?
// This Command
Route::get(‘/’,’HomeController@getIndex’);
// Is doing this.
$app->make(‘router’)->get(‘HomeController@getIndex’);
// This Command
Input::get(‘email’);
// Is doing this.
$app->make(‘request’)->get(‘email’);
// This Command
$appName = Config::get(‘application.name’);
// Is doing this.
$fileSystem = new Filesystem(...);
$fileLoader = new Fileloader($fileSystem);
$config = new Config($fileLoader,’dev’);
$appName = $config->get(‘application.name’);
MODEL
VIEW
CONTROLLER
•Model
•View
•Controller
•Eloquent ORM
•Blade Engine
•Controller
Model
class People extends Eloquent {
protected $table = 'people';
protected $primaryKey = 'id';
public function summary(){
return truncate($this->content,100);
}
}
• Query Builder
• Eloquent
Controller
• Basic Controller
• Controller Filter
• Implicit Controller
• RESTful Resource Controller
View
• Blade is a quick and relatively simple template engine for rendering
you views.
• Features many of the core functions found in other popular engines
such as twig and smarty
• Since blade views are PHP scripts, you can use PHP code directly in
your templates (with caution)
• Inheritance-driven to allow for multiple layouts, sections, etc
Layout
<html>
<head></head>
<body>
<header>This is Header</header>
<section class="content">
@yield('content')
</section>
<footer>copyright@made by cool me</footer>
</body>
</html>
@extends('layout')
@section('content')
<p>This is partial content</p>
@stop
layout.blade.php
home.blade.php
CREATE MIGRATION
ROLLBACK MIGRATION
SEEDING DATA
MIGRATIONVersion Control for Database Schema
WHY
ARE
GOOD?
Schema Builder
public function up()
{
Schema::create('people', function(Blueprint $table)
{
$table->increments('id');
$table->string('first_name');
$table->string('last_name');
$table->string('role')->default('star');
$table->string('bio')->nullable();
});
}
public function down()
{
Schema::drop('people');
}
IoC Container( Inversion of Control )
Quick word on Dependencies
• A dependency is when one component (typicaly an object) relies on
another for its operation.
• Dependencies should be passed (injected) into an object via its
constructor or setter methods and not instatiated inside it
• Directly instatiating dependencies is considered bad practise as it
reduces scalability and flexibility, plus it make objects difficult to test
in isolation.
Inversion of Control
public function sendEmail(){
$mailer = new Mailer();
$mailer->send();
}
public function sendEmail(){
$mailer = App::make(‘mailer’)
$mailer->send();
}
Hard-coded source dependecy
IoC Resolution
Dependency Example
class Computer{
protected $processor;
public function __construct(){
$this->processor = new ProcessorIntelI7();
}
}
class Computer{
protected $processor;
public function __construct(ProcessorInterface $processor){
$this->processor = $processor;
}
}
App::bind('keranjang_belanja',function($app){
return new KeranjangBelanja(new Pelanggan,new Belanjaan);
});
$keranjangBelanja = App::make('keranjang_belanja');
Singletons
App::singleton('user_session',function($app){
return new UserSession($_SESSION['REMOTE_ADDR']);
});
// First call to creates the object...
$userSession = App::make('user_session');
// Second call just fetches...
$userSession = App::make('user_session');
IoC Automatic Dependency Resolution
If you type-hint the dependencies passed into a constructor then
Laravel can do the rest!
class Computer{
protected $processor;
public function __construct(ProcessorInterface $processor){
$this->processor = $processor;
}
}
App::bind('ProcessorInterface','ProcessorIntelI7');
$computer = App:make('Computer');
IoC Container + Facades = Laravel
Walkthrough
Q&SQuestion and Sharing XD

More Related Content

PPTX
Laravel introduction
PPTX
Hire laravel-php-developers- Hire Laravel Programmers
PDF
Laravel Introduction
PPTX
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
PDF
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
PPTX
Laravel ppt
PPTX
A introduction to Laravel framework
PPTX
Laravel overview
Laravel introduction
Hire laravel-php-developers- Hire Laravel Programmers
Laravel Introduction
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
An Introduction to the Laravel Framework (AFUP Forum PHP 2014)
Laravel ppt
A introduction to Laravel framework
Laravel overview

What's hot (20)

PPTX
Getting started with laravel
PPTX
Introduction to laravel framework
PPTX
Laravel Tutorial PPT
PDF
Web Development with Laravel 5
PDF
Laravel
PPT
What Is Hobo ?
PPTX
Laravel Eloquent ORM
ODP
Projects In Laravel : Learn Laravel Building 10 Projects
PPTX
Intro to Laravel
PDF
Getting to know Laravel 5
PPTX
API Development with Laravel
PDF
Why Laravel?
PDF
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
 
PDF
Laravel 5 Annotations: RESTful API routing
PPTX
Introduction to Laravel Framework (5.2)
PDF
Digpen 7: Why choose Laravel?
PDF
Laravel presentation
PDF
Laravel tutorial
PPTX
2011 NetUG HH: ASP.NET MVC & HTML 5
PPTX
What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)
Getting started with laravel
Introduction to laravel framework
Laravel Tutorial PPT
Web Development with Laravel 5
Laravel
What Is Hobo ?
Laravel Eloquent ORM
Projects In Laravel : Learn Laravel Building 10 Projects
Intro to Laravel
Getting to know Laravel 5
API Development with Laravel
Why Laravel?
Deep Dive: Alfresco Core Repository (... embedded in a micro-services style a...
 
Laravel 5 Annotations: RESTful API routing
Introduction to Laravel Framework (5.2)
Digpen 7: Why choose Laravel?
Laravel presentation
Laravel tutorial
2011 NetUG HH: ASP.NET MVC & HTML 5
What's New in Laravel 5 (Laravel Meetup - 23th Apr 15, Yogyakarta, ID)
Ad

Similar to Laravel Meetup (20)

PPTX
Introduction_to_Laravel_Background DOCUMENTATION.pptx
PPTX
Introduction_to_Laravel_Simple DUCUMENTATION.pptx
PDF
Introduction to Laravel
PPTX
What-is-Laravel and introduciton to Laravel
PPTX
Laravel : A Fastest Growing Kid
PPTX
What-is-Laravel-23-August-2017.pptx
PDF
Introduction to Flask Micro Framework
PPTX
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
PDF
An insight to microsoft platform
PDF
Building Scalable Applications with Laravel
PPTX
Amis conference soa deployment. the dirty tricks using bamboo, nexus and xl ...
PPTX
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
PDF
Laravel 4 presentation
PPTX
Lecture 2_ Intro to laravel.pptx
PPTX
Create Salesforce online IDE in 30 minutes
PPT
Rajnish singh(presentation on oracle )
PPTX
Introduction to web application development with Vue (for absolute beginners)...
PDF
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
PPTX
Web presentation
PPTX
My Saminar On Php
Introduction_to_Laravel_Background DOCUMENTATION.pptx
Introduction_to_Laravel_Simple DUCUMENTATION.pptx
Introduction to Laravel
What-is-Laravel and introduciton to Laravel
Laravel : A Fastest Growing Kid
What-is-Laravel-23-August-2017.pptx
Introduction to Flask Micro Framework
44CON 2014 - Pentesting NoSQL DB's Using NoSQL Exploitation Framework, Franci...
An insight to microsoft platform
Building Scalable Applications with Laravel
Amis conference soa deployment. the dirty tricks using bamboo, nexus and xl ...
ZZ BC#7 asp.net mvc practice and guideline by NineMvp
Laravel 4 presentation
Lecture 2_ Intro to laravel.pptx
Create Salesforce online IDE in 30 minutes
Rajnish singh(presentation on oracle )
Introduction to web application development with Vue (for absolute beginners)...
Devops continuousintegration and deployment onaws puttingmoneybackintoyourmis...
Web presentation
My Saminar On Php
Ad

Laravel Meetup

Editor's Notes

  • #6: RESTful Routing Use simple Closures to respond to requests to your application. It couldn't be easier to get started building amazing applications. Command Your Data Ships with the amazing Eloquent ORM and a great migration system. Works great on MySQL, Postgres, SQL Server, and SQLite. Beautiful Templating Use native PHP or the light-weight Blade templating engine. Blade provides great template inheritance and is blazing fast. You'll love it. Ready For Tomorrow Build huge enterprise applications, or simple JSON APIs. Write powerful controllers, or slim RESTful routes. Laravel is perfect for jobs of all sizes. Proven Foundation Laravel is built on top of several Symfony components, giving your application a great foundation of well-tested and reliable code. Composer Powered Composer is an amazing tool to manage your application's third-party packages. Find packages on Packagist and use them in seconds. Great Community Whether you're a PHP beginner or architecture astronaut, you'll fit right in. Discuss ideas in the IRC chat room, or post questions in the forum. Red, Green, Refactor Laravel is built with testing in mind. Stay flexible with the IoC container, and run your tests with PHPUnit. Don't worry... it's easier than you think.
  • #8: PSR : PHP Specification Request Single Reponsibility Swiss Army knife Open/Closed Principle open for extension, butclosed for modification. Liskov Subtitution Principle Likov's Substitution Principle states that if a program module is using a Base class, then the reference to the Base class can be replaced with a Derived class without affecting the functionality of the program module. Rectangle & Square class. Interface Segregation Principle Pemisahan = segregation Instead of one fat interface many small interfaces are preferred based on groups of methods, each one serving one submodule. Dependency Inversion Principle A. High-level modules should not depend on low-level modules. Both should depend on abstractions. B. Abstractions should not depend upon details. Details should depend upon abstractions. class PDFReader { private $book; function __construct(PDFBook $book) { $this->book = $book; } function read() { return $this->book->read(); } } class PDFBook { function read() { return "reading a pdf book."; } } The MIT License is a free software license originating at the Massachusetts Institute of Technology (MIT). It is a permissive free software license, meaning that it permits reuse within proprietary software provided all copies of the licensed software include a copy of the MIT License terms and the copyright notice.
  • #12: Keyword : Dependency Manager, github, project --prefer-dist: Reverse of --prefer-source, composer will install from dist if possible. This can speed up installs substantially on build servers and other use cases where you typically do not run updates of the vendors. It is also a way to circumvent problems with git if you do not have a proper setup. --no-dev: Skip installing packages listed in require-dev Issue : Permission app/storage (+w) --prefer-source: There are two ways of downloading a package: source and dist. For stable versions composer will use the dist by default. The source is a version control repository. If --prefer-source is enabled, composer will install from source if there is one. This is useful if you want to make a bugfix to a project and get a local git clone of the dependency directly. --prefer-dist: Reverse of --prefer-source, composer will install from dist if possible. This can speed up installs substantially on build servers and other use cases where you typically do not run updates of the vendors. It is also a way to circumvent problems with git if you do not have a proper setup. --ignore-platform-reqs: ignore php, hhvm, lib-* and ext-* requirements and force the installation even if the local machine does not fulfill these. --dry-run: If you want to run through an installation without actually installing a package, you can use --dry-run. This will simulate the installation and show you what would happen. --dev: Install packages listed in require-dev (this is the default behavior). --no-dev: Skip installing packages listed in require-dev. --no-autoloader: Skips autoloader generation. --no-scripts: Skips execution of scripts defined in composer.json. --no-plugins: Disables plugins. --no-progress: Removes the progress display that can mess with some terminals or scripts which don't handle backspace characters. --optimize-autoloader (-o): Convert PSR-0/4 autoloading to classmap to get a faster autoloader. This is recommended especially for production, but can take a bit of time to run so it is currently not done by default.
  • #13: Server Configuration which php php –ini php –i > phpinfo.txt apt-get install php5-mcrypt service apache2 restart Sometimes you might get the message “php5-mcrypt is already the newest version“. If so, install with: apt-get --reinstall install php5-mcrypt ?
  • #14: The Goal!!
  • #15: The Goal!!
  • #16: Virtual Box + Vagrant (box) - Nginx 1.6 PHP 5.5.12 MySQL (database ready) Postgres (database ready) Redis --- Memcached Beanstalkd Node + Grunt, Gulp, & Bower Laravel Envoy Fabric (Phyton)
  • #17: The Goal!!
  • #18: Like Homestead in the cloud
  • #22: The /app directory remains, but it is now home to only the http and application layers of the project(s). In the example above, three related applications share the project space; Admin, API & Client. App/lang The Laravel Lang class provides a convenient way of retrieving strings in various languages, allowing you to easily support multiple languages within your application. The app directory, as you might expect, contains the core code of your application. We'll explore this folder in more detail soon. The bootstrap folder contains a few files that bootstrap the framework and configure autoloading. The config directory, as the name implies, contains all of your application's configuration files. The database folder contains your database migration and seeds. The public directory contains the front controller and your assets (images, JavaScript, CSS, etc.). The resources directory contains your views, raw assets (LESS, SASS, CoffeeScript), and "language" files. The storage directory contains compiled Blade templates, file based sessions, file caches, and other files generated by the framework. The tests directory contains your automated tests. The vendor directory contains your Composer dependencies Request enters public/index.php file. bootstrap/start.php file creates Application and detects environment. Internal framework/start.php file configures settings and loads service providers. Application app/start files are loaded. Application app/routes.php file is loaded. Request object sent to Application, which returns Response object. Response object sent back to client.
  • #28: Route::get('user', array('before' => 'old', 'uses' => 'UserController@showProfile')); Route::get('user', array('before' => 'auth|old', function() { return 'You are authenticated and over 200 years old!'; })); Route::get('user', array('before' => array('auth', 'old'), function() { return 'You are authenticated and over 200 years old!'; }));
  • #31: Facades provide a "static" interface to classes that are available in the application's IoC container.  Facede are static wrappers to instatiated objects. The provide a quick readable way to access laravel various componenets. Big Misconception : laravel is not a static framework. Justru since these facades are syntatic sugar you can bypass them for mocks and tests! You can easly create your own facades or ‘rewire’ the existing one.
  • #32: In the context of a Laravel application, a facade is a class that provides access to an object from the container. 
  • #35: - Active Record style Easy To Use Book::all(); Book::find(); Book::where(‘title’,’like’,’%laravel%’); $book = new Book(); $book->title = ‘Laravel’; $book->author = ‘Taylor Otwell’; $book->save(); $affectedRows = User::where('votes', '>', 100)->update(array('status' => 2)); $user = User::find(1); $user->delete();
  • #36: use Illuminate\Database\Eloquent\SoftDeletingTrait; class User extends Eloquent { use SoftDeletingTrait; protected $dates = ['deleted_at']; } $table->softDeletes(); // for migration $users = User::withTrashed()->where('account_id', 1)->get(); $user->posts()->withTrashed()->get(); $users = User::onlyTrashed()->where('account_id', 1)->get(); $user->restore();
  • #37: public function missingMethod($parameters = array()) { }
  • #38: @extends(‘master’) -> include @yield(‘content’,’[opt] default content’) -> placeholder pair with @section(‘content’) <tag> @stop @include(‘view.name’) -> sub view Echoing : triple curly brace syntax to escape any HTML entities in the content. {{-- This comment will not be in the rendered HTML --}}
  • #41: php artisan migrate:make create_users_table php artisan migrate php artisan migrate:rollback // last migration php artisan migrate:reset //Rollback all migrations Rollback all migrations and run them all again php artisan migrate:refresh php artisan migrate:refresh –seed php artisan db:seed --class=UserTableSeeder
  • #42: The Laravel Schema class provides a database agnostic way of manipulating tables. It works well with all of the databases supported by Laravel, and has a unified API across all of these systems.
  • #43: The IoC container is a way of automaticaly passing dependencies into your objects and/or storing them for later retrieval
  • #44: Relies bergantung
  • #48: We can threat th IoC container as a registry ,initializing object once and returning them on subsequent calls.
  • #50: The static classess used to control Laravel are known as Facades. Facades are nothing more than wrappers to the IoC Container Therefore, every time you use facades such as DB, Config, View, Route, Etc you are create and/or fetching a pre-registered object! You can easily create your own application-specific IoC bindings and facades