5. 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
7. 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
9. 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
10. 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
15. 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
19. 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
26. 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(){...}
}
27. 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!';
}));
28. • Easy to understand
• Expressiveness and Elegance
The Syntactic Sugar
Auth::check();
Input::get();
Cookie::make();
Event::subscribe();
Pesan::kirim(); // your own facade example
31. 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’);
34. Model
class People extends Eloquent {
protected $table = 'people';
protected $primaryKey = 'id';
public function summary(){
return truncate($this->content,100);
}
}
37. 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
43. 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.
44. 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
45. 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;
}
}
48. 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');
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.
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.
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.
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 ?
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.
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!';
}));
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.
In the context of a Laravel application, a facade is a class that provides access to an object from the container.
- 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();
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();
public function missingMethod($parameters = array()) {
}
@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 --}}
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
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.
The IoC container is a way of automaticaly passing dependencies into your objects and/or storing them for later retrieval
Relies bergantung
We can threat th IoC container as a registry ,initializing object once and returning them on subsequent calls.
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