laravel 4



What's old?
What's new?



by Maks


Old:

  • Clean and Eloquent syntax.
  • Separation of elements
  • Awesome community
  • Joy to code with
  • Same Creator and visionary - Taylor
  • Still PHP, but better (like traits in PHP 5.4)

New:

  • Command line is a lot more powerful
  • Testability (all components Unit Tested)
  • Mail component built in
  • Packages instead of Bundles (7000 vs 200)
  • PHP >= 5.3.7 
  • Resourceful routes + controllers
  • PSR-0 camelCase instead of snake_case

Command line magic

php artisan controller:make PhotoController

Produces RESTful controller:

<?php

class PhotoController extends BaseController {
	public function index(){}
	public function create(){}
	public function store(){}
	public function show($id){}
	public function edit($id){}
	public function update($id){}
	public function destroy($id){}
}

In Routes.php :

Route::resource('photo', 'PhotoController');

Command Line Magic

Actions handled by Resource controller:
Verb Path Action 
 GET /resource                                               index 
 GET /resource/create                               create 
 POST /resource                                            store 
 GET /resource/{id}                                      show 
 GET /resource/{id}/edit                           edit 
 PUT/PATCH /resource/{id}                   update 
 DELETE /resource/{id}                             destroy

More Artisan commands

php artisan list to see all

migration
controller
db seed
command:make
workbench - creating new packages
serve


Make your own commands

app/commands

php artisan command:make FooCommand

Testing and TDD

Support for PHPUnit out of the box

Example of a test:
$response = $this->call('GET', 'user/profile');

DOM crawler:

$this->assertCount(1, $crawler->filter('h1:contains("Hello World!")'));


Packages : 

  • MongoDB
  • LessPHP
  • Bootstrapper
  • Former
  • Coffee - coffescript compiler
  • Flatten
  • 6994 more packages.

MAIL

Easy email with Swiftmailer built in.
Mail::send('emails.welcome', $data, function($m)
{
	$m->to('maks@example.com', 'Maks')->subject('Welcome!');
});

Title

Gone : STR:: and HTML:: helpers


Find replacements as Composer Packages:
bigelephant/string
and 
meido/str

Different Routing

Route::get('user/{name?}', function($name = 'John')
{
    return $name;
});

Route::get('user/{name}', function($name)
{
    //
})
->where('name', '[A-Za-z]+');

Route::get('user/{id}', function($id)
{
    //
})
->where('id', '[0-9]+');

Sub domain Routing

Route::group(array('domain' => '{account}.myapp.com'), function()
{
    Route::get('user/{id}', function($account, $id)
    {
        //
    });
});


Route prefixing

Route::group(array('prefix' => 'admin'), function()
{
    Route::get('user', function()
    {
        //
    });
});

Resources: 



laravel 4

By msurguy

laravel 4

  • 6,243