Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Laravel 5 New Features

2,373 views

Published on

These are the new features sldes from my Laravel 5 tutorial session at php[tek] 2015

Published in: Technology
  • Be the first to comment

Laravel 5 New Features

  1. 1. Laravel 5 New Features Joe Ferguson
  2. 2. Before we begin Have Virtualbox (virtualbox.org) Installed Have VirtualBox Extension Pack Installed Have Vagrant (vagrantup.com) Installed run: vagrant box add laravel/homestead
  3. 3. New Directory Structure
  4. 4. Laravel 5 Directory App directory now "Your Application" / "Entry point to app” Laravel 4 Artisan Commands -> Console in App folder Web stuff in Http Controllers all have name space filters.php -> Broken out into separate classes/files. More focus on Service Providers -> Filter Service Providers No more global.php -> Use service providers Removed models directory. Can be just in app folder. PSR-4 default Don't like the app namespace? artisan app:name MyApplication
  5. 5. Blade Changes Laravel 4 uses {{ to echo and {{{ To echo escaped Laravel 5 {{ and {{{ will echo escaped and {!! is used to echo raw Biggest impact is likely form helpers: {!! Form::open() !!}
  6. 6. Commands Commands (app/Commands) - Message containing only info needed to do something Command Handler (app/Handlers/Commands) - Class that does something in response to a command Command Bus - Allows dispatch of commands, matches commands to handlers Self handling commands just need a handle() method on the command & implements SelfHandling
  7. 7. Events Events (app/Events) Events have handlers (similar to Commands) Bind Events via appProvidersEventServiceProvider.php Events inform the system something happened VS demanding action from the system
  8. 8. Form Requests Special class for validating and authorizing form submissions Each class has rules() (returns array) and authorize() (returns boolean) methods Benefit of rules & authorize being methods is you can perform logic Type Hinting your forms to the Form Request will automatically validate your forms If validation fails, errors will be available to the view and redirected back. This happens because the FormRequestServiceProvider listens for anything being resolved is instance of FormRequest and calls the validate method.
  9. 9. Helpers view() - Get a View instance for the given view path action() - Generate a URL for a given controller action app_path() - Get the fully qualified path to the app directory asset() - Generate a URL for an asset. Routing – get(), delete(), put()
  10. 10. Route Caching artisan route:cache Serializes your routes.php Benefits: Faster routing Drawback: Must run artisan route:clear on every routes.php change
  11. 11. Middleware Implements decorator pattern. request -> does work -> returns object to next layer Laravel uses middleware for Encrypting/Decrypting cookies, Reading/Writing Sessions artisan make:middleware MyMiddleware (app/Http/Middleware) Middleware registered in app/Http/Kernel.php Can run before or after the request has been processed. Easiest example would be auth
  12. 12. Controller Method Injection Can inject dependencies into methods, no longer via constructor Purpose is to help developers write cleaner code
  13. 13. Changes to Illuminate Packages Form or HTML helpers no longer in Core, must be pulled in via composer. add "laravelcollective/html": "~5.0" to composer update config/app.php
  14. 14. Elixir API for defining basic Gulp tasks for your app. Requires nodejs Put your sass/less files in resources/assets/sass|less Can trigger sass/less/phpunit/phpspec, combine stylesheets
  15. 15. Socialite Easy to use social logins with oauth Supports Facebook, Twitter, Google, Github, and Bitbucket
  16. 16. Contracts Set of interfaces that define the core services provided by the framework Depend on abstractions, not concrete dependencies. Write code that doesn't have to be aware of the laravel framework
  17. 17. Upgrade from 4.2 to 5 Fresh install Laravel 5 Update Dependencies /Packages Namespace (somewhat optional for now) Migrate environment variables Move routes to app/Http/routes.php Move controllers to app/Http/Controllers (add this to classmap) Copy route bindings to boot() in app/Providers/RouteServiceProvider.php Add route facade to RouteServiceProvider.php to continue using Route facade CSRF is now global. Use middleware to disable if needed Move models to app/Models. Add app/Models to classmap in composer.json Update your user auth to use Laravel 5’s auth system Move commands to app/Console/Commands. Add app/Console/Commands to classmap in composer.json Move migrations to database/migrations, Database Seeds to database/seeds … and more!
  18. 18. Upgrade from 4.2 to 5 http://laravel.com/docs/5.0/upgradeFresh install Laravel 5 Update Dependencies /Packages Namespace (somewhat optional for now) Migrate environment variables Move routes to app/Http/routes.php Move controllers to app/Http/Controllers (add this to classmap) Copy route bindings to boot() in app/Providers/RouteServiceProvider.php Add route facade to RouteServiceProvider.php to continue using Route facade CSRF is now global. Use middleware to disable if needed Move models to app/Models. Add app/Models to classmap in composer.json Update your user auth to use Laravel 5’s auth system Move commands to app/Console/Commands. Add app/Console/Commands to classmap in composer.json Move migrations to database/migrations, Database Seeds to database/seeds … and more!
  19. 19. Homestead “Laravel Homestead is an official, pre-packaged Vagrant "box" that provides you a wonderful development environment without requiring you to install PHP, HHVM, a web server, and any other server software on your local machine. No more worrying about messing up your operating system! Vagrant boxes are completely disposable. If something goes wrong, you can destroy and re- create the box in minutes!”
  20. 20. What’s in the box: • Ubuntu 14.04 • PHP 5.6 • HHVM • Nginx • MySQL • Postgres • Redis • NodeJS • Bower • Grunt • Gulp • Beanstalkd • Memcached • Laravel Envoy Fabric + HipChat Extension + more!
  21. 21. Getting Homestead Install the box: vagrant box add laravel/homestead
  22. 22. Getting Homestead If you have PHP installed locally: composer global require "laravel/homestead=~2.0" Make sure to place the ~/.composer/vendor/bin directory in your PATH so the homestead executable is found when you run the homestead command in your terminal.
  23. 23. Homestead 2.0 Significant change over previous 1.x versions Uses homestead from your home folder Less vagrant stuff in your projects (if you don’t like that sort of thing)
  24. 24. How I use Homestead https://github.com/svpernova09/HomesteadSkeleton Drop in Homestead files to project Each project has an isolated vagrant environment Easier to share dev environment settings

×