Laravel Logo

Introducing Laravel

An Eloquent PHP Framework

Ryan Durham
Stage Right Labs

ryan at stagerightlabs dot com

stagerightlabs

Laravel

Laravel

Isn't PHP a dead horse?

Not at all!

PHP 5.3+

  • Objects & Abstract Classes
  • Namespacing
  • Closures
  • Native JSON Support
  • 5.4: Traits

Why use a Framework?

  • No need to reinvent the wheel
  • Repetive tasks made easy
  • Faster development
  • Security
  • Community support

Laravel Features

  • Database Migrations & Seeding
  • Command Line Tools: Artisan
  • Environments
  • ORM: Eloquent
  • Templating: Blade
  • Integrated Authentication
  • Events / Observables
  • Queue Support: Beanstalkd, Redis, etc
  • Internationalization Support
  • Dependency Injection & Inversion of Control

Benefits

  • Ease of Use
  • Flexibility
  • Testability / TDD
  • Extendablity (via Composer and packagist.org)
  • Large Development Community
  • Personal Growth

Requirements

  • PHP 5.3.7 or higher
  • MCrypt PHP Extension
Composer

Composer

Package Management for PHP

http://getcomposer.org

Installation:



$ curl -sS https://getcomposer.org/installer | php
$ sudo mv composer.phar /usr/local/bin/composer
    

Creating a New Laravel Project



$ composer create-project laravel/laravel your-project-name
    

  • Make app/storage directory writeable
  • Edit app/config options: Database, Email, etc
  • Make sure Apache's mod_rewrite is enabled
  • Optional: Configure Apache Virtual Host Config

First Steps

Routing

app/routes.php

// Application Routes

Route::get('/login', function()
{
    return View::make('users.login');
});

// Resourceful Routes - Default CRUD Routes
Route::resource('groups', 'GroupController');


// Controller Routes - CRUD Routes + Anyting Else
Route::controller('users', 'UserController');
    

Views - Master Layout

app/views/layouts/master.blade.php


<!DOCTYPE html>
<html lang="en">
<head>
    <title>
        @section('title')
    </title>
    <link rel="stylesheet" href="@{{ asset('css/bootstrap.min.css') }}">
    <link rel="stylesheet" href="@{{ asset('css/bootstrap-theme.min.css') }}">
</head>
<body>
    <div class="navbar navbar-inverse navbar-fixed-top">
      
    </div>
    
    <div class="container">
        @yield('content')
    </div>
</body>
</html>
    

Views - Basic Example

app/views/users/login.blade.php


@extends('layouts.master')

@section('title', 'Log In')

@section('content')
<div class="row">
<div class="col-md-4 col-md-offset-4">
{{ Form::open(array('action' => 'UserController@login')) }}
  <h2 class="form-signin-heading">Sign In</h2>
  {{ Form::text('email', null, array('class' => 'form-control', 'placeholder' => 'Email', 'autofocus')) }}
  {{ Form::password('password', array('class' => 'form-control', 'placeholder' => 'Password'))}}
  {{ Form::submit('Sign In', array('class' => 'btn btn-primary'))}}
{{ Form::close() }}
</div>
</div>
@stop
    

Controllers

app/controllers/UserController.php


class UserController extends BaseController {

public function getIndex()
{
    return view('users.index')->with('users', User::all());
}

public function postLogin(Request $request)
{
    $email    = $request->input('email');
    $password = $request->input('password');

    if (Auth::attempt(['email' => $email, 'password' => $password]))
    {
        return redirect()->intended('dashboard');
    }

    return redirect('login');
}
}
    

Downsides

  • Not ideal for Shared Hosting Environments
  • Still Very New - Things Change Quickly
  • Documentation doesn't cover the entire codebase
  • Lack of contract work

Further Resources

Sentinel


Laravel Implementation of Sentry Auth System

Thank you!

ryan at stagerightlabs dot com

stagerightlabs

Stage Right Labs Logo