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>
        
        
            @section('title')
        
        <link rel="stylesheet" href="{{ asset('css/bootstrap.min.css') }}">
        <link rel="stylesheet" href="{{ asset('css/bootstrap-theme.min.css') }}">
    </head>
    <body>
        
        
        
@yield('content')
</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

<?php
class UserController extends BaseController {

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

    public function postLogin()
    {
        $email    = Input::get('email');
        $password = Input::get('password');

        if (Auth::attempt(array('email' => $email, 'password' => $password)))
        {
            return Redirect::intended('dashboard');
        }

        return Redirect::to('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