Digpen 7: Why choose Laravel?

46
Why Choose Laravel?

Transcript of Digpen 7: Why choose Laravel?

Page 1: Digpen 7: Why choose Laravel?

Why ChooseLaravel?

Page 2: Digpen 7: Why choose Laravel?

"Always start your presentation with a quote"

1@rosstuck

Page 3: Digpen 7: Why choose Laravel?

Why Choose Laravel?1. Introduction

2. The Problems of Legacy Code

3. Introducing Laravel

4. Laravel in Action

Page 4: Digpen 7: Why choose Laravel?

1. Introduction

Page 5: Digpen 7: Why choose Laravel?

Who are you

John?

Page 6: Digpen 7: Why choose Laravel?

John Blackmore

4 31 Years Old

4 Married with 2 Children

4 14 Years Experience in Web

4 Technical Architect at Crowdcube

Page 7: Digpen 7: Why choose Laravel?

The Architect

Page 8: Digpen 7: Why choose Laravel?

What isCrowdcube?

Page 9: Digpen 7: Why choose Laravel?

4 Equity Crowdfunding Platform

4 £40m Invested, 90k Investors, 150 Pitches

4 Self funded on our own platform, three times.

Page 10: Digpen 7: Why choose Laravel?

2. The Problems of Legacy Code

Page 11: Digpen 7: Why choose Laravel?

Legacy Code Problems

4 Spaghetti code

4 Limited code re-use

4 Multiple code styles

4 Security vulnerabilities

Page 12: Digpen 7: Why choose Laravel?

The Solution?

Page 13: Digpen 7: Why choose Laravel?

Our Solution at Crowdcube

4 Develop new features on a framework

4 Agreed coding style (modified PSR-2)

4 Best practises (SoC, DRY, SOLID)

4 Git with Git-Flow

Page 14: Digpen 7: Why choose Laravel?

What is a Framework?

Page 15: Digpen 7: Why choose Laravel?

Frameworkan essential supporting structure of

a building, vehicle, or object.

a basic structure underlying a system, concept, or text

Page 16: Digpen 7: Why choose Laravel?

Software Frameworkan abstraction in which software providing generic

functionality can be selectively changed by additional user-written code, thus providing application-specific software

Page 17: Digpen 7: Why choose Laravel?

say what?

Page 18: Digpen 7: Why choose Laravel?

A software framework is 80% of your application already written for you.

Page 19: Digpen 7: Why choose Laravel?

Why use a framework?

4 Enables rapid development

4 Stable and well tested

4 Community support

4 Easy to recruit developers

Page 20: Digpen 7: Why choose Laravel?

Hey, I could buildmy own framework?

Page 21: Digpen 7: Why choose Laravel?

Bad IdeaIn most cases

Page 22: Digpen 7: Why choose Laravel?

Why you should not build your own

4 You don't have time

4 There will be bugs

4 Difficult to recruit developers

4 Why reinvent the wheel?

Page 23: Digpen 7: Why choose Laravel?

Framework Options

Page 24: Digpen 7: Why choose Laravel?
Page 25: Digpen 7: Why choose Laravel?

3. Introducing Laravel

Page 26: Digpen 7: Why choose Laravel?

Laravel Features4 MVC Framework

4 Convention over Configuration

4 Coded to Interfaces:

4 Authentication, Databases, Caching, Queueing

4 Blade templating engine

Page 27: Digpen 7: Why choose Laravel?

Why Crowdcube Chose Laravel4 Low learning curve

4 Well documented

4 Excellent test coverage

4 Large active community

4 Built on Symfony components

Page 28: Digpen 7: Why choose Laravel?

You can use Laravel features right now

Page 29: Digpen 7: Why choose Laravel?

Standalone Components4 Illuminate - https://github.com/illuminate

4 Can be used within non-laravel projects

4 Crowdcube actively uses:

4 illuminate/database

4 illuminate/events

4 illuminate/queue

Page 30: Digpen 7: Why choose Laravel?

4. Laravel in ActionExamples from Crowdcube

Page 31: Digpen 7: Why choose Laravel?

Legacy Crowdcube Platform4 Single LAMP server

4 Procedural PHP4 code

4 Tightly coupled to MySQL

4 No caching

Page 32: Digpen 7: Why choose Laravel?

Where do you start?

Page 33: Digpen 7: Why choose Laravel?

ProblemServer load was extremely peaky

Cause: serving static assets from the application server

Page 34: Digpen 7: Why choose Laravel?

Solution: Amazon Cloudfront CDN

4 Cloudfront sits in front of existing server

http://www.crowdcube.com/images/some_image.jpghttp://cdn.crowdcube.com/images/some_image.jpg

4 80% reduction in CPU usage

Page 35: Digpen 7: Why choose Laravel?

ProblemExisting Database Schema

Page 36: Digpen 7: Why choose Laravel?

Solution: Eloquent Models

4 Eloquent maps database tables to PHP models

class Pitches extends Eloquent {}Pitches::whereTitle('Crowdcube'); // returns Crowdcube pitch

4 CRUD operations now simplified in code$user = User::create(['name'=>'John', 'email'=>'[email protected]']);$user->save(); // This can trigger additional events

INSERT INTO `users` (name, email) VALUES ('John', '[email protected]');

Page 37: Digpen 7: Why choose Laravel?

ProblemTalking between legacy code

and Laravel code

Page 38: Digpen 7: Why choose Laravel?

Solution: Eventing and Worker Queues

4 Amazon SQS Queues

4 Events fired in legacy code

Event::fire('pitch.funded', ['pitch'=>'1234']);

4 Events captured, jobs queued

Queue::push('SendFundedEmail', ['pitch' => '1234'])

4 Queues processed in Laravel

Page 39: Digpen 7: Why choose Laravel?

ProblemVisible lag on some pages

e.g. home page, search

Cause: Slow SQL queries

Page 40: Digpen 7: Why choose Laravel?

Solution: Query Caching$activePitches = Cache::remember('pitches.active', 10, function(){ return Pitches::active()->get();});

4 Supports APC, Memcached, Redis out the box

4 Typical search query ~400ms from MySQL

4 Same query using file driver <10ms

Page 41: Digpen 7: Why choose Laravel?

ProblemNot enough time to talk about

all the really cool stuff

Page 42: Digpen 7: Why choose Laravel?

Other Cool Stuff4 Query Scoping

4 View Composers

4 Model Binding

4 Artisan CLI

4 Homestead / Forge

Page 43: Digpen 7: Why choose Laravel?

Laravel Resources4 Official Docs - http://laravel.com/docs

4 Laracasts - https://laracasts.com

4 Code Bright - https://leanpub.com/codebright

4 Culttt (Philip Brown) - http://culttt.com

Page 44: Digpen 7: Why choose Laravel?

Unless someone like you cares a whole awful lot, Nothing is going to get

better. It’s not.1

The Lorax

Page 45: Digpen 7: Why choose Laravel?

Questions?

Page 46: Digpen 7: Why choose Laravel?

Thank You!Twitter: @johnblackmore

Email: [email protected]

Feedback: http://lanyrd.com/sdfcyt