laravel 5 new features
TRANSCRIPT
Before we begin
Have Virtualbox (virtualbox.org) Installed
Have VirtualBox Extension Pack Installed
Have Vagrant (vagrantup.com) Installed
run: vagrant box add laravel/homestead
Laravel 5 DirectoryApp 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
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() !!}
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
Events
Events (app/Events)
Events have handlers (similar to Commands)
Bind Events via app\Providers\EventServiceProvider.php
Events inform the system something happened VS demanding action from the system
Form RequestsSpecial 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.
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()
Route Caching
artisan route:cache
Serializes your routes.php
Benefits: Faster routing
Drawback: Must run artisan route:clear on every routes.php change
MiddlewareImplements 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
Controller Method Injection
Can inject dependencies into methods, no longer via constructor
Purpose is to help developers write cleaner code
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
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
Socialite
Easy to use social logins with oauth
Supports Facebook, Twitter, Google, Github, and Bitbucket
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
Upgrade from 4.2 to 5Fresh 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!
Upgrade from 4.2 to 5
http://lar
avel.com
/docs/5.0
/upgrade
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!
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!”
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!
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.
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)
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