laravel introduction

35

Upload: ahmad-shah-hafizan-hamidin

Post on 01-Dec-2014

340 views

Category:

Technology


5 download

DESCRIPTION

Introduction to Laravel 4 framework

TRANSCRIPT

Page 1: Laravel Introduction
Page 2: Laravel Introduction

whoami• Ahmad Shah Hafizan Hamidin • 27 years old • Been developing for > 7 years • Laravel & Orchestra fanboy • https://www.github.com/ahmadshah • @penjajah • kuasamalaya

Page 3: Laravel Introduction

So What is Laravel?

Page 4: Laravel Introduction

+ +

Page 5: Laravel Introduction

Why so many Laravel?

laravel/laravel!The framework structure and boilerplate codes !laravel/framework!The core of laravel framework or the kernel !Illuminate The namespace for every laravel framework components!

Page 6: Laravel Introduction

What do we need?

• A webserver (Apache2/NGINX) • PHP 5.4 or above • Database engines (MySQL/PostgreSQL/MSSQL) • PHP mcrypt extension • Composer

Page 7: Laravel Introduction

Composer!

• Remember PEAR? • Awesome PHP package management • Making developer lives easier • Manage application dependencies • http://getcomposer.org/ • http://packagist.com/

Page 8: Laravel Introduction

How to get Laravel?!

via Laravel installer!> composer global require “laravel/installer=~1.1”

> laravel new my-application

!

via Composer!> composer create-project laravel/laravel my-

application

Page 9: Laravel Introduction
Page 10: Laravel Introduction

Laravel Setup

• Make app/storage directory writable

• Update public/.htaccess if you are using alias

• Update app/config/database.php to connect

to your database

Page 11: Laravel Introduction

Eloquent, Blade and ControllerM V C

Page 12: Laravel Introduction

Laravel Routes

• Handles the HTTP requests • GET, POST, PUT, PATCH, DELETE • All application routes are defined inside app/routes.php

• Can accept Closures or controller namespace

Page 13: Laravel Introduction

Laravel RoutesRoute with Closure!Route::get(‘foobar’, function () {

return ‘Welcome to FooBar!’;

});

!

Route with Controller!Route::get(‘foobar’, ‘FoobarController@index’);

Page 14: Laravel Introduction

Laravel Controllers

• Handles the HTTP requests • GET, POST, PUT, PATCH, DELETE • Controllers are kept under app/controllers

• Laravel naming convention: FoobarController

• Extends Illuminate\Routing\Controller class

Page 15: Laravel Introduction

Laravel Resourceful Controllers

• Handles the HTTP requests • GET, POST, PUT, PATCH, DELETE • Predefine controller methods to handle

the HTTP verbs • index, show, create, store, edit,

update, and destroy

Page 16: Laravel Introduction

Laravel Resourceful!Controllers

Route with Resource Controller!Route::resource(‘foobar’, ‘FoobarController’);

Page 17: Laravel Introduction

Laravel Views• The presentation layer of an application • Can accept either vanilla PHP or Blade

files • View files are located under app/views

directory • Can accept array arguments

Page 18: Laravel Introduction

Laravel Views

Route with view!Route::get(‘foobar’, function () {

return View::make(‘foobar’);

});

Page 19: Laravel Introduction

Laravel Blade

Page 20: Laravel Introduction

Laravel Blade

• Laravel default templating engine • Files need to use .blade.php extension

• Driven by inheritance and sections • Extensible for adding new custom control

structures

Page 21: Laravel Introduction

Laravel BladeMaster layout!<!doctype html>

<body>

@yield(‘content’)

</body>

</html>

!

Child layout!@extends(‘layout.master’)

@section(‘content’)

@stop

Page 22: Laravel Introduction

Laravel Eloquent• Laravel ORM component • Simple ActiveRecord implementation • Each tables can be represented with a

“Model” file • Model files are located under app/models

directory • Extends Illuminate\Database\Eloquent\Model

class

Page 23: Laravel Introduction

Laravel Fluent

• Laravel SQL query builder component • Write SQL query in a more elegant and readable

way

Page 24: Laravel Introduction

Laravel Filters

• Control the behaviour of a route • Process request before or after • Filters are located inside app/filters.php

• Can be attached directly to route or controller • Can be in either Closure or filter class

Page 25: Laravel Introduction

Laravel Auth

• Laravel user authentication component • Provide a basic functionalities to authenticate users • Does not come with ACL / RBAC • Utilizes app/models/User.php

• Laravel does not come with a user table by default

Page 26: Laravel Introduction

Tinkering with the artisan

Page 27: Laravel Introduction
Page 28: Laravel Introduction

Laravel Artisan

• Laravel CLI • Uses the Symfony Console component • Manage table migrations, seed tables,

create resourceful controllers and many more • Developer best friend!

Page 29: Laravel Introduction

Service Providers & Facades

Page 30: Laravel Introduction

SOLID PrinciplesSingle Responsibility Principle!a class should have only one responsibility !Open/Closed Principle!open for extension and closed for modification !Liskov Substitution Principle Subtypes must be substitutable for their base types!

Page 31: Laravel Introduction

SOLID PrinciplesInterface Segregation Principle!many client-specific interfaces are better !Dependency Inversion Principle!depends on abstraction !!

Page 32: Laravel Introduction

Laravel IOC

• Inversion Of Control • Manages class dependencies • Based on dependency injection method • Dependencies are injected at run-time • Allowing dependencies to be easily swapped

Page 33: Laravel Introduction

Laravel Service Providers

• Act like a component bootstrap • Group related IoC registrations in one place • Can also run other functionalities like

artisan commands

Page 34: Laravel Introduction

Laravel Facades

• Provide static interfaces to classes • Classes are resolved via IoC containers • Laravel is full with facades such as View,

Cache, Config and others

Page 35: Laravel Introduction

Laravel Workbench

• A tool to help develop laravel based components • Scaffold the necessary boilerplates • We do not commit/ship workbench directory