a introduction to laravel framework

52
A INTRODUCTION TO LARAVEL FRAMEWORK [email protected] [email protected], [email protected] Hanoi. Jan 09, 2016

Upload: phu-luong-trong

Post on 10-Feb-2017

626 views

Category:

Art & Photos


0 download

TRANSCRIPT

Page 1: A introduction to Laravel framework

A INTRODUCTION TOLARAVEL [email protected]@gmail.com, [email protected]. Jan 09, 2016

Page 2: A introduction to Laravel framework

CONTENT

About MegaAds Technical Team Laravel Framework Overview Laravel v4 Laravel v5 MegaAds & Laravel

Page 3: A introduction to Laravel framework

MEGAADS TECHNICAL TEAM

Business Coupon Affiliate in US Retailer in Vietnam

Systems Coupon affiliate websites Link Crawler, Link Management Retail websites Order management Inventory management CRM Tracker SEO supplier system

Page 4: A introduction to Laravel framework

MEGAADS TECHNICAL TEAM

Solutions PHP, AngularJS, Laravel Framework Java, Spring Framework NodeJS, Adu Framework: https://github.com/phult/adu Search engine: Elasticsearch Message queue: Gearman Database: MySQL, Redis

Page 5: A introduction to Laravel framework

LARAVEL OVERVIEW

Developer: Taylor Otwell Release: June 2011 Stable Release: 5.2.7, Dec 31, 2015 PHP: 5.3 Docs: http://laravel.com/docs, https://laracasts.com/

Page 6: A introduction to Laravel framework

LARAVEL OVERVIEW

Page 7: A introduction to Laravel framework

LARAVEL OVERVIEW

Page 8: A introduction to Laravel framework

LARAVEL OVERVIEW

Page 9: A introduction to Laravel framework

LARAVEL 4

Composer Artisan CLI Folder structure Main classes Blade template Databases ORM

Validation Cache  Event Queue IoC

Page 10: A introduction to Laravel framework

COMPOSER

A tool for dependency management in PHP. It allows you to declare the libraries your project depends on and it will manage (install/update) them for you

PHP: 5.3.2+ Equivalent:

Java: maven, gradle Ruby: gem Nodejs: npm

Page 11: A introduction to Laravel framework

COMPOSER

Composer.json

Page 12: A introduction to Laravel framework

COMPOSER

Command php composer.phar install php composer.phar update php composer.phar dump-autoload

Page 13: A introduction to Laravel framework

ARTISAN CLI

php artisan command

Page 14: A introduction to Laravel framework

PROJECT FOLDER STRUCTURE

App Config Controllers Database Lang Models Start Storage Tests Views

Bootstrap Public vendor

Page 15: A introduction to Laravel framework

MAIN CLASSES

Config App.php: debug, timezone, providers Cache.php: drivers file/redis/mecache/apc/array Database.php: connections, driver mysql/redis/mongo… Mail.php Queue: driver sync/beanstalkd/sqs/iron/redis Session.php: drivers

file/cookie/database/redis/mecache/apc/array View.php: 'paths' => array(__DIR__.'/../views'),

Page 16: A introduction to Laravel framework

MAIN CLASSES

Routes.php

Page 17: A introduction to Laravel framework

MAIN CLASSES

Filters.php

Page 18: A introduction to Laravel framework

BLADE TEMPLATE

views/front-end/layout/master.blade.php

Page 19: A introduction to Laravel framework

BLADE TEMPLATE

index.blade.php

Page 20: A introduction to Laravel framework

DATABASE: MIGRATION

Migration

Page 21: A introduction to Laravel framework

DATABASE: MIGRATION

Migration: php artisan migrate php artisan migrate:rollback php artisan migrate:reset

Page 22: A introduction to Laravel framework

DATABASE: SEEDING

Seeding

Page 23: A introduction to Laravel framework

DATABASE: SEEDING

Seeding php artisan db:seed --class=UserTableSeeder

Page 24: A introduction to Laravel framework

MODEL/ORM

Models/User.php

Page 25: A introduction to Laravel framework

MODEL/ORM

Create: User::create([“username”=>”ABC”]);

Update User::find(1)->update([“username”=>”ABC”]);

Delete User::find(1)->delete

Page 26: A introduction to Laravel framework

MODEL/ORM

Get: $user = User::find(1); $roles = User::find(1)->roles; $users = User::where(“status”,”=”,”active”

->orWhere(“status”,”=”,”active”)->find([“id”,”username”,”status”]);

DB::table(“user”)->where(“status”,”=”,”active”)->orWhere(“status”,”=”,”active”)->find([“id”,”username”,”status”]);

Page 27: A introduction to Laravel framework

MODEL/ORM

EventUser::creating(function($user) { if ( ! $user->isValid()) return false; });User::created(function($user) {});User::updating(function($user) {});User::deleting(function($user) {});

Page 28: A introduction to Laravel framework

VALIDATION

Page 29: A introduction to Laravel framework

CACHE

Drivers: file/redis/mecache/apc/array

Page 30: A introduction to Laravel framework

EVENTS

Subscribe to an event

Fire a event

Page 31: A introduction to Laravel framework

QUEUES

Publish a job onto the queue

Job handler

Queue::push('SendEmail@fire', array('message' => $message),'emails');

Page 32: A introduction to Laravel framework

IOC

Bind to container

Usage

Page 33: A introduction to Laravel framework

LARAVEL 5

Page 34: A introduction to Laravel framework

WHAT IS NEW

Page 35: A introduction to Laravel framework

NEW FOLDER STRUCTURE

App/models -> remove App/Http (Controllers,Middleware,Requests)

App/start -> App/Providers App/views -> App/Resourses

Page 36: A introduction to Laravel framework

DOTENV

Instead of a variety of confusing, nested environment configuration directories, Laravel 5 now utilizes DotEnv by Vance Lucas

Page 37: A introduction to Laravel framework

ROUTE MIDDLEWARE

HTTP middleware provide a convenient mechanism for filtering HTTP requests entering your application

php artisan route:middleware DemoMiddleware

Page 38: A introduction to Laravel framework

ROUTE & CONFIG CACHE

php artisan route:cache php artisan route:clear php artisan config:cache php artisan config:clear

Page 39: A introduction to Laravel framework

FORM REQUESTS

Laravel 5.0 introduces form requests, automatically be validated.

Page 40: A introduction to Laravel framework

LARAVEL SCHEDULER

Developers have generated a Cron entry for each task they need to schedule

Page 41: A introduction to Laravel framework

LARAVEL ELIXIR

Elixir makes it a cinch to get started using Gulp to compile your Less, Sass, and CoffeeScript …

Page 42: A introduction to Laravel framework

AUTHENTICATION

User registration, authentication, and password reset controllers are now included out of the box, as well as simple corresponding views

Page 43: A introduction to Laravel framework

LARAVEL SOCIALITE

Socialite supports Facebook,Twitter, Google, and GitHub

Page 44: A introduction to Laravel framework

EVENT & LISTENER

Event classes are typically stored in the app/Events directory, while their listeners are stored in app/Listeners

Page 45: A introduction to Laravel framework

FLYSYSTEM

Integrations : Laravel - Symfony - Zend Framework - CakePHP - Yii 2 …

Adapters : Local - Amazon Web Services - Rackspace Cloud Files - Dropbox - Ftp - Sftp - Zip - WebDAV - PHPC - Azure Blob Storagev

Page 46: A introduction to Laravel framework

TINKER / PSYSH

php artisan tinker

Page 47: A introduction to Laravel framework

CONTRACTS

Laravel's Contracts are a set of interfaces that define the core services provided by the framework

Page 48: A introduction to Laravel framework

MEGAADS & LARAVEL

Controller: Frontend, Backend, Services: RESTful webservice View with AngularJS: AJAX request SOA with IoC, AbtractService class Seach engine: Elasticsearch Async, RPC with Message queue: gearman

Page 49: A introduction to Laravel framework

SEARCH SERVICE CONFIG

Page 50: A introduction to Laravel framework

MEGAADS & LARAVEL

RPC

Gearman serverWeb App (PHP)

Node.js app

Java app

Web App (PHP)

Page 51: A introduction to Laravel framework

MEGAADS & LARAVEL

Producer (PHP)

Page 52: A introduction to Laravel framework

MEGAADS & LARAVEL

Consumer(Java)