Chris van Daele / 06.02.2015 / QuestBack, Köln Laravel 5 Framework The PHP Framework for Web Artisans
Simplicity is the essence of happiness. - Cedric Bledsoe
Was bisher geschah 06/2011: Laravel 1 11/2011: Laravel 2 02/2012: Laravel 3 05/2013: Laravel 4 02/2015: Laravel 5 (4.3) Taylor Otwell
Larawhat? Das Ecosystem. laravel/laravel Framework Struktur und Demo Code laravel/homestead Lokale Laravel Entwicklungsumgebung laravel/framework Laravel Kernel Forge Deploymentsystem in der Cloud Illuminate Laravel Komponenten Namespace innerhalb des Frameworks Laracasts Screencasts. It s amazing!
Features, Features, Features! Expressive, beautiful Syntax Version 5 Features: Eloquent ORM (ActiveRecord Implementation) Routing (Restful) IoC Container Dependeny Injection Migrations, Schema Builder & Seeds Authentication Testable Validation CLI Illuminate Contracts Middleware (Filter) Command Bus Flysystem (Local, Amazon S3, Rackspace) Elixir (Gulp Api Wrapper) Socialite (OAuth) Scheduler
Symfony meets Laravel symfony/console symfony/debug symfony/finder symfony/http-foundation symfony/finder symfony/process symfony/routing symfony/security-core symfony/translation symfony/var-dumper symfony/http-kernel
Thats not all there is even more! monolog/monolog league/flysystem nesbost/carbon swiftmailer/swiftmailer vlucas/phpdotenv ircmaxel/password-compat
Illuminaten! Auth Bus Cache Config Console Container Contracts Cookie Database Encryption Events Exception Filesystem Foundation Hashing Http Pagination Pipeline Queue Redis Routing Session Support Translation Validation View
StackPHP - Der Kernel Symfony HttpKernelInterface middlewares Authentifizierung CSRF Protection Encrypt Cookies Session Handling
The Inversion Of Control (IoC) IoC Binding $this->app->bind('foobar', function($app) { return new FooBar($app['SomethingElse']); }); $this->app->singleton('foobar', function($app) { return new FooBar($app['SomethingElse']); }); $this->app->bind( 'App\Contracts\SomeInterface', 'App\Services\ConcreteImplementation' ); IoC Resolving $foobar = $this->app->make('foobar')->get('key');
Facades It s all static? Route::get('/', 'HomeController@showWelcome'); Facade erstellen: 1. Ioc Binding 2. Facade Class $app['router']->get('/', 'HomeController@showWelcome'); 3. Facade Alias Configuration IoC Container
MVC = EBC Model = Eloquent ORM View = Blade Template Engine Controller = Controller
Model - Eloquent class User extends Eloquent { class Post extends Eloquent { public function posts() { return $this->hasmany('post'); } public function user() { return $this->belongsto('user'); } } }
Model - Eloquent // User auslesen $users = User::all(); // Neuen User anlegen $user = new User; $user $user $user = User::where('name', '=', 'John Doe')->posts(); = User::find(1); = User::findOrFail(1); $user->name = 'John Doe'; $user->save(); // User löschen var_dump($user->name); $user = User::destroy(1);
View Blade Template <!-- Stored in resources/views/layouts/master.blade.php --> <html> <body> <div class="container"> @yield('content') </div> </body> </html> <!-- Stored in resources/views/layouts/home.blade.php --> @extends('layouts.master') @section('content') Hello, {{ $name }}. @foreach ($users as $user) <p>this is user {{ $user->id }}</p> @endforeach @stop
Controller use App\Http\Requests\PurchasePodcastRequest; class PodcastController extends Controller { use DispatchesCommands; } public function purchasepodcast(purchasepodcastrequest $request, $podcastid) { $this->dispatch( new PurchasePodcast(Auth::user(), Podcast::findOrFail($podcastId)) ); }
CommandBus class PurchasePodcast extends Command implements SelfHandling { protected $user, $podcast; public function construct(user $user, Podcast $podcast) { $this->user = $user; $this->podcast = $podcast; } } public function handle() { // Handle the logic to purchase the podcast. event(new PodcastWasPurchased($this->user, $this->podcast)); }
Ressourcen http://laravel.com http://laracasts.com http://laravel.io/forum http://laracasts.com/discuss http://laravel-news.com http://mattstauffer.co http://daylerees.com http://fideloper.com/tag/laravel http://laracon.eu (25.08. 26.08.2015, Amsterdam. YAY!)
Fin. Vielen Dank für die Aufmerksamkeit!