Pablo Chiappetti

@p4bloch

LARAVEL

An introduction to its magic

About me

@p4bloch

Ninja Developer @Bikestorming

Full Stack Nerd

Argentinian

Boca Juniors Fan

About this talk

Introduction for PHP developers

If you like it, then go read the docs

How Laravel solves common problems

about laravel

VERSIONS 4 & 5

RELEASES EVERY 6 MONTHS

LONG TERM SUPPORT

EMBRACES THE COMMUNITY

Homestead

Laravel's own vagrant box

  • Ubuntu 14.04
  • PHP 5.6
  • HHVM
  • Nginx
  • MySQL
  • Postgres
  • Node 
  • Redis
  • Memcached
  • Beanstalkd

demo

Installation & Project Structure

artisan

Laravel's CLI tool

Routing

MIDDLEWARE

Filter every request entering your app.

php artisan make:middleware TestMiddleware

Databases

MIGRATIONS

php artisan make:migration create_posts_table

Version control for your database

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

ELOQUENT

php artisan make:model Post

Laravel's Active Record ORM

COLLECTIONS

RELATIONSHIPS

SEEDERS

php artisan make:seeder PostSeeder

Run the seeder

php artisan db:seed
$factory->define(App\User::class, function (Faker\Generator $faker) {
    return [
        'name' => $faker->name,
        'email' => $faker->email,
        'password' => bcrypt(str_random(10)),
        'remember_token' => str_random(10),
    ];
});

FACTORIES

$user = factory(App\User::class)->make();

$users = factory(App\User::class, 3)->make();

DEPENDENCY INJECTION

METHOD INJECTION

QUEUEs

Integration with BeanstalkdIronMQ,

Amazon SQS and Redis

php artisan make:job SendConfirmationEmail --queued

How to use it

MAIL

EVENTS

Event::fire(new PostWasPublished($post));

Observer implementation

Event

Listener

Listener

Listener

BROADCAST

// PostWasPublished.php
class PostWasPublished extends Event implements ShouldBroadcast {

    public $post;

    public function broadcastOn()
    {
        return ['posts'];
    }   
}

Websockets implementation out of the box

// main.js
socket.on('posts:PostWasPublished', function(message){
    console.log(message.user);
});

TESTING

PHPUnit support out of the box

Mocking

Factories

DatabaseTransactions trait

DatabaseMigrations trait

public function testPhotoCanBeUploaded()
{
    $this->visit('/upload')
         ->name('File Name', 'name')
         ->attach($absolutePathToFile, 'photo')
         ->press('Upload')
         ->see('Upload Successful!');
}

OTHER COOL STUFF

Blade Template Engine

Caching

Envoy

Localization

Form Requests

Flysystem included

Elixir

Lumen (micro framework)

Forge (server management)

RESOURCES

Laracasts.com

Laracon Youtube Channel

Laravel.io

Thank you!

Laravel: An introduction to its magic

By Pablo Chiappetti

Laravel: An introduction to its magic

Slides of my talk at PHP TLV meetup on 07/28/2015. Introduction to Laravel and its most useful features.

  • 1,204