Sobre Mí

 Pablo Chiappetti 

Full Stack Web Developer.
Multimedial Designer.
 Laravel & Web Dev

Lead Developer


Laravel

EL Framework PHP

que faltaba



¿Qué es laravel?


Un framework MVC de PHP moderno

Destacados en la comunidad









@jeffrey_way
Creador de Laracasts.com

@ShawnMcCool
Creador de  Laravel.io

@taylorotwell

Creador de
Laravel

Principales Características

( tcc cómo Laravel te salva la vida )

  • Aritsan CLI
  • Eloquent ORM
  • DB Migrations
  • Blade (Templates)
  • Routing Poderoso
  • Eventos
  • Cache
  • Autenticación
  • Queues

Artisan CLI


php artisan list  migrate                     Run the database migrations
  optimize                    Optimize the framework for better performance
  routes                      List all registered routes
  serve                       Serve the application on the PHP development 

server
  down                        Put the application into maintenance mode
  up                          Bring the application out of maintenance mode

cache
  cache:clear                 Flush the application cache

controller
  controller:make             Create a new resourceful controller

db
  db:seed                     Seed the database with records

generate
  generate:controller         Generate a new controller.
  generate:form               Dump form HTML for a model
  generate:migration          Generate a new migration.
  generate:model              Generate a new model.
  generate:pivot              Generate a pivot table
  generate:resource           Generate a resource.
  generate:scaffold           Generate scaffolding for a resource.
  generate:seed               Generate a seed file.
  generate:test               Generate a PHPUnit test class.
  generate:view               Generate a new view.

key
  key:generate                Set the application key

migrate
  migrate:install             Create the migration repository
  migrate:make                Create a new migration file
  migrate:refresh             Reset and re-run all migrations
  migrate:reset               Rollback all database migrations
  migrate:rollback            Rollback the last database migration

queue
  queue:listen                Listen to a given queue
  queue:subscribe             Subscribe a URL to an Iron.io push queue
  queue:work                  Process the next job on a queue

Routing


GET
// app/routes.php
Route::get('/', function()
{
    return 'Hello World';
});

POST

Route::post('foo/bar', function()
{    return Input::all();
});

ROUTING


Recibir Parámetros de la URL
Route::get('user/{id}', function($id)
{    return User::find($id)->get();
});

Asociar una ruta a un método
Route::get('user/{id}', 'UserController@showProfile');

ROUTING


Laravel soporta Resourceful Controllers

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


Route
::get('photos', 'PhotoController@index');
Route::get('photos/create', 'PhotoController@create');
Route::post('photos', 'PhotoController@store');
Route::get('photos/{id}', 'PhotoController@show');
............


REST

Verb Path Action Route Name
GET /photos index resource.index
GET /photos/create create resource.create
POST /photos store resource.store
GET /photos/{id} show resource.show
GET /photos/{id}/edit edit resource.edit
PUT/PATCH /photos/{id} update resource.update
DELETE /photos/{id} destroy

Filtros

Se ejecutan antes y/o despues de cada
request a la ruta que lo apliquemos.

Route::get('/administrator', ['before' => 'admin'], function()
{    // podemos asumir que el usuario esta logueado.
    return 'Admin page!';
});
Route::filter('admin', function()
{
    if (!Auth::check())
    {
        // Redirect al login
    }
});

Eloquent ORM







$users = User::all(); // Todos los usuarios de la DB
User::create(['nombre' => 'Pablo']); // Crea al usuarioUser::find(1)->delete(); // Borra al usuarioUser::find(1)->nombre; // Pablo
// app/models/User.php

class User extends Eloquent {    // Todo opcional
    protected $table = 'usuarios';    protected $fillable = ['nombre', 'mail'];    protected $guarded = 'id';
protected $hidden = 'password';
}

Relaciones


$user
= Post::whereSlug('el-post')->user;


$comments = Post::find(1)->comments;
class Post extends Eloquent {
public function comments() { return $this->hasMany('Comment'); }
public function user() { return $this->belongsTo('User'); }
}

Paginación


$someUsers = User::where('votes', '>', 100)->paginate(15);
// En la vista
{{ $someUsers->links() }}


Fluent Query Builder

http://laravel.com/docs/queries

Métodos también disponibles utilizando un modelo de Eloquent.
DB::table('users')-> se reemplaza por User::

// Todos los usuarios$users = DB::table('users')->get();
// El primer usuario cuyo campo 'name' sea John$user = DB::table('users')->where('name', 'John')->first();
// Solo el valor del campo nombre$name = DB::table('users')->where('name', 'John')->pluck('name');
// Varios filtros$users = DB::table('users')
                    ->where('votes', '>', 100)
                    ->orWhere('name', 'John')
                    ->get();
// JoinsDB::table('users')
            ->join('contacts', 'users.id', '=', 'contacts.user_id')
            ->join('orders', 'users.id', '=', 'orders.user_id')
            ->select('users.id', 'contacts.phone', 'orders.price');

Migrations


Control de Versión para nuestra base de datos.



Rollback
php artisan migrate:rollback
php artisan migrate:make --create="users" create_users_table
php artisan migrate:make add_votes_to_user_table --table=users

Jeffrey Way's Generators


php artisan generate:migration create_posts_table
--fields="title:string, body:text"




php artisan migrate

Blade Template Engine


// Archivo en /app/views/layout.blade.php<html>
    <body>
        HTML general a todo el proyecto, botoneras, etc.
        <div class="container">
            @yield('content') // Contenido variable para cada vista
        </div>
    </body>
</html>


Extender un Layout


@extends('layouts.master')

@section('content')
    <p>This is my body content.</p>
@stop

PHP parser y flow control


@for ($i = 0; $i < 10; $i++)
    The current value is {{ $i }}
@endfor

@foreach ($users as $user)
    <p>This is user {{ $user->id }}</p>
@endforeach

@while (true)
    <p>I'm looping forever.</p>
@endwhile
@if (condition) <p>I'm looping forever.</p>@elseif(condition) <p>I'm looping forever.</p>@else <p>I'm looping forever.</p>
@endif {{ date() }} es igual a <?php echo date(); ?>

Todo lo demás



¿Qué más?


- Eventos
- Form Helpers
- Redirect a rutas
- Auth
- Response, API
- Packages
- Dependency Injection
- Patrón de Repositorios
- Testing
- Seguridad

Links Útiles

Laravel.io #laravel

Laravel 4

By Pablo Chiappetti

Laravel 4

  • 2,824
Loading comments...

More from Pablo Chiappetti