SlideShare a Scribd company logo
1 of 68
Download to read offline
Adventures in Laravel 5
Joe Ferguson
February 4th 2015
Who Am I?
Joe Ferguson
PHP Developer
Twitter: @JoePFerguson
Organizer of @MemphisPHP
@NomadPHP Lightning Talks
Passionate about Community
Before we begin
Have Virtualbox (virtualbox.org) Installed
Have VirtualBox Extension Pack Installed
Have Vagrant (vagrantup.com) Installed
run: vagrant box add laravel/homestead
New(ish) Toys in Laravel
New Directory Structure
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
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 appProvidersEventServiceProvider.php
Events inform the system something happened VS demanding
action from the system
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 an 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
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
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
Implicit Route Model Binding
Laravel will automatically resolve type-hinted Eloquent model's
defined in routes or controller actions whose variable names match a
route segment name.
Laravel 5.2https://laravel.com/docs/5.2/routing#route-model-binding
API Rate Limiting
Limit the amount of times a user can access your API with the
Throttle middleware.
Laravel 5.2https://laracasts.com/series/whats-new-in-laravel-5-2/episodes/2
Will return HTTP Code 429 (Too many requests)
Auth & Password Resets
New artisan command make:auth generates scaffolding for you.
Laravel 5.2https://laracasts.com/series/whats-new-in-laravel-5-2/episodes/3
Validating Arrays
Laravel 5.2https://laracasts.com/series/whats-new-in-laravel-5-2/episodes/4
Authentication Drivers
Laravel 5.2
Easily have different authentication drivers for multiple
authenticatable models or user tables.
Useful to allow users from an admins table be able to log
in as well as users from a users table.
Functional Testing Is Easy!
Upgrade from 4.2 to 5.x
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!
Upgrade from 4.2 to 5.x
https://laravel.com/docs/5.1/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!
Quick note on versions
5.1 LTS bug fixes for 2 years, security fixes for 3 years
Non LTS: bug fixes for 6 months, security fixes for 1 year
5.1 is currently the only LTS version
Which version should you use?
5.2 for my own projects
5.1 for client projects
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 7.0
• HHVM
• Nginx
• MySQL
• Postgres
• Redis
• NodeJS
• Bower
• Grunt
• Gulp
• Beanstalkd
• Memcached
• Laravel Envoy
Fabric + HipChat Extension + more!
Getting Homestead
Install the box:
vagrant box add laravel/homestead
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.x & 3.x
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)
3.x will give you PHP 7
How I use Homestead
Install Homestead
http://laravel.com/docs/5.1/homestead#per-project-installation
Getting Started with Laravel
Database, Migrations, Seeding
database/
factories/ - Default Model Attributes
migrations/ - Version control for your DB Schema
seeds/ - Sample / Test Data for your DB
Database, Migrations, Seeding
Routing
app/
Http/
routes.php
Layouts
resources/
views/
layouts/
app.blade.php
Views
resources/
views/
tasks.blade.php
Time to do stuff!
Open
Laravel-5.2-basic-quickstart
Basic Quick Start
https://laravel.com/docs/5.2/quickstart
If you already have Vagrant, Run:
`./vendor/bin/homestead make`
`vagrant up`
Run the migration: `php artisan migrate`
Viewing the Migration
Laravel-5.2-basic-quickstart/
database/
migrations/
2015_10_27_141258_create_tasks_table.php
Viewing the Model
Laravel-5.2-basic-quickstart/app/Task.php
Viewing the Routes
Laravel-5.2-basic-quickstart/app/Http/routes.php
Exercise 1 Hints
Add / edit migration to create
users table
Add / edit User model
Add routes (just like task)
Add / edit User Views
You can safely disregard any authentication related to users
Exercise 1 Solution
To see a possible solution
checkout the branch “exercise-1”
git checkout exercise-1
Exercise 2
Assign users to tasks as you create
them
When listing tasks, show the user
they have assigned them
When listing users, show how many
tasks they have assigned them
You can safely disregard any authentication related to users
Exercise 2 Hints
Add / edit migration to create
users table
Add / edit User model
Add routes (just like task)
Add / edit User Views
You can safely disregard any authentication related to users
Exercise 2 Solution
To see a possible solution
checkout the branch “exercise-2”
git checkout exercise-2
Exercise 3
Write Tests for User Functionality
Write Tests for Task Functionality
Exercise 3 Hints
Use Model Factories to seed test data
Make sure the task is saved to the DB
Make sure the user is saved to the DB
Ensure the user delete request succeeds
Ensure the task delete request succeeds
Ensure the index page loads and contains data
You can safely disregard any authentication related to users
Exercise 3 Solution
To see a possible solution
checkout the branch “exercise-3”
git checkout exercise-3
Easy Stuff Right?
Let’s clean up a bit
Exercise 4
Move “Create” Forms to own views
Move “Current” html to own views
Move Create/Delete User Functionality to
Controller method
Move Create/Delete Task Functionality to
Controller method
Exercise 4 Hints
Use `php artisan make:controller` to
scaffold
Utilize your tests to make sure you
didn’t break anything:
`./vendor/bin/phpunit`
You can safely disregard any authentication related to users
Using Laravel Facades
Using Static Methods:
`User::all()`
`User::find(1);
`User::where(‘user_id`, 1)->get()
`User::where(‘email’, ‘joe@joeferguson.me’)->get();
Using Dependency Injection
Using Injected Object
`$this->user->all()`
`$this->user->find(1);
`$this->user->where(‘user_id`, 1)->get()
`$this->user->where(‘email’, ‘joe@joeferguson.me’)->get();
Exercise 5
Update your controllers to inject your
models instead of using static methods
(Facades)
Exercise 5 Hints
Make sure you “use AppModelName”
Utilize your tests to make sure you
didn’t break anything:
`./vendor/bin/phpunit`
You can safely disregard any authentication related to users
Exercise 6
Implement index view for tasks
Implement index view for users
Implement edit functionality for tasks
Add tests for your new routes & methods
Exercise 6 Hints
Route Controller
Go forth and develop!
Feedback!
https://joind.in/talk/f8132
Joe Ferguson
Twitter: @JoePFerguson
Email: joe@joeferguson.me
Freenode: joepferguson
Contact Info:
Adventures in Laravel 5 SunshinePHP 2016 Tutorial

More Related Content

What's hot

Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web ArtisansRaf Kewl
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New FeaturesJoe Ferguson
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 Joe Ferguson
 
All Aboard for Laravel 5.1
All Aboard for Laravel 5.1All Aboard for Laravel 5.1
All Aboard for Laravel 5.1Jason McCreary
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5Darren Craig
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should knowPovilas Korop
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Vikas Chauhan
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5Soheil Khodayari
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentationToufiq Mahmud
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.SWAAM Tech
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Lorvent56
 
Knowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkKnowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkBukhori Aqid
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel frameworkPhu Luong Trong
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Dilouar Hossain
 

What's hot (20)

Laravel 5
Laravel 5Laravel 5
Laravel 5
 
Laravel for Web Artisans
Laravel for Web ArtisansLaravel for Web Artisans
Laravel for Web Artisans
 
Laravel 5 New Features
Laravel 5 New FeaturesLaravel 5 New Features
Laravel 5 New Features
 
MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5 MidwestPHP 2016 - Adventures in Laravel 5
MidwestPHP 2016 - Adventures in Laravel 5
 
All Aboard for Laravel 5.1
All Aboard for Laravel 5.1All Aboard for Laravel 5.1
All Aboard for Laravel 5.1
 
What's New In Laravel 5
What's New In Laravel 5What's New In Laravel 5
What's New In Laravel 5
 
Laravel 5.4
Laravel 5.4 Laravel 5.4
Laravel 5.4
 
10 Laravel packages everyone should know
10 Laravel packages everyone should know10 Laravel packages everyone should know
10 Laravel packages everyone should know
 
Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1Laravel Beginners Tutorial 1
Laravel Beginners Tutorial 1
 
Web Development with Laravel 5
Web Development with Laravel 5Web Development with Laravel 5
Web Development with Laravel 5
 
Laravel presentation
Laravel presentationLaravel presentation
Laravel presentation
 
Presentation laravel 5 4
Presentation laravel 5 4Presentation laravel 5 4
Presentation laravel 5 4
 
Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.Laravel - Website Development in Php Framework.
Laravel - Website Development in Php Framework.
 
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
Laravel Starter Kit | Laravel Admin Template-ChandraAdmin
 
Laravel Tutorial PPT
Laravel Tutorial PPTLaravel Tutorial PPT
Laravel Tutorial PPT
 
Knowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP frameworkKnowing Laravel 5 : The most popular PHP framework
Knowing Laravel 5 : The most popular PHP framework
 
A introduction to Laravel framework
A introduction to Laravel frameworkA introduction to Laravel framework
A introduction to Laravel framework
 
Laravel overview
Laravel overviewLaravel overview
Laravel overview
 
Laravel Introduction
Laravel IntroductionLaravel Introduction
Laravel Introduction
 
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...Laravel development (Laravel History, Environment Setup & Laravel Installatio...
Laravel development (Laravel History, Environment Setup & Laravel Installatio...
 

Similar to Adventures in Laravel 5 SunshinePHP 2016 Tutorial

Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravelConfiz
 
Laravel (8) php_framework_handbook__start_from_zer_18604872_(z-lib.org)
Laravel (8) php_framework_handbook__start_from_zer_18604872_(z-lib.org)Laravel (8) php_framework_handbook__start_from_zer_18604872_(z-lib.org)
Laravel (8) php_framework_handbook__start_from_zer_18604872_(z-lib.org)ssuser337865
 
All the Laravel Things – Up & Running to Making $$
All the Laravel Things – Up & Running to Making $$All the Laravel Things – Up & Running to Making $$
All the Laravel Things – Up & Running to Making $$Joe Ferguson
 
laravel-interview-questions.pdf
laravel-interview-questions.pdflaravel-interview-questions.pdf
laravel-interview-questions.pdfAnuragMourya8
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with LaravelAbuzer Firdousi
 
An Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP ProgrammersAn Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP Programmersjphl
 
Hidden things uncovered about laravel development
Hidden things uncovered about laravel developmentHidden things uncovered about laravel development
Hidden things uncovered about laravel developmentKaty Slemon
 
What's New in AppFuse 2.0
What's New in AppFuse 2.0What's New in AppFuse 2.0
What's New in AppFuse 2.0Matt Raible
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxSaziaRahman
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfKaty Slemon
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsJim Jeffers
 
Laravel : A Fastest Growing Kid
Laravel : A Fastest Growing KidLaravel : A Fastest Growing Kid
Laravel : A Fastest Growing KidEndive Software
 
Laravel & Composer presentation - extended
Laravel & Composer presentation - extendedLaravel & Composer presentation - extended
Laravel & Composer presentation - extendedCvetomir Denchev
 

Similar to Adventures in Laravel 5 SunshinePHP 2016 Tutorial (20)

Getting started with laravel
Getting started with laravelGetting started with laravel
Getting started with laravel
 
Web services with laravel
Web services with laravelWeb services with laravel
Web services with laravel
 
Laravel (8) php_framework_handbook__start_from_zer_18604872_(z-lib.org)
Laravel (8) php_framework_handbook__start_from_zer_18604872_(z-lib.org)Laravel (8) php_framework_handbook__start_from_zer_18604872_(z-lib.org)
Laravel (8) php_framework_handbook__start_from_zer_18604872_(z-lib.org)
 
All the Laravel Things – Up & Running to Making $$
All the Laravel Things – Up & Running to Making $$All the Laravel Things – Up & Running to Making $$
All the Laravel Things – Up & Running to Making $$
 
laravel-interview-questions.pdf
laravel-interview-questions.pdflaravel-interview-questions.pdf
laravel-interview-questions.pdf
 
Web service with Laravel
Web service with LaravelWeb service with Laravel
Web service with Laravel
 
An Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP ProgrammersAn Introduction to Websphere sMash for PHP Programmers
An Introduction to Websphere sMash for PHP Programmers
 
Laravel intallation
Laravel intallationLaravel intallation
Laravel intallation
 
Hidden things uncovered about laravel development
Hidden things uncovered about laravel developmentHidden things uncovered about laravel development
Hidden things uncovered about laravel development
 
What's New in AppFuse 2.0
What's New in AppFuse 2.0What's New in AppFuse 2.0
What's New in AppFuse 2.0
 
Lecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptxLecture 2_ Intro to laravel.pptx
Lecture 2_ Intro to laravel.pptx
 
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdfThe Ultimate Guide to Laravel Performance Optimization in 2022.pdf
The Ultimate Guide to Laravel Performance Optimization in 2022.pdf
 
Laravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php frameworkLaravel 5.3 - Web Development Php framework
Laravel 5.3 - Web Development Php framework
 
Building Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in RailsBuilding Mobile Friendly APIs in Rails
Building Mobile Friendly APIs in Rails
 
Article laravel 8
Article laravel 8Article laravel 8
Article laravel 8
 
Laravel
LaravelLaravel
Laravel
 
cakephp UDUYKTHA (1)
cakephp UDUYKTHA (1)cakephp UDUYKTHA (1)
cakephp UDUYKTHA (1)
 
Laravel : A Fastest Growing Kid
Laravel : A Fastest Growing KidLaravel : A Fastest Growing Kid
Laravel : A Fastest Growing Kid
 
Laravel & Composer presentation - extended
Laravel & Composer presentation - extendedLaravel & Composer presentation - extended
Laravel & Composer presentation - extended
 
Laravel 9_ Unlock the Exciting Features Here!.pptx
Laravel 9_ Unlock the Exciting Features Here!.pptxLaravel 9_ Unlock the Exciting Features Here!.pptx
Laravel 9_ Unlock the Exciting Features Here!.pptx
 

More from Joe Ferguson

Modern infrastructure as code with ansible cake fest 2021
Modern infrastructure as code with ansible cake fest 2021Modern infrastructure as code with ansible cake fest 2021
Modern infrastructure as code with ansible cake fest 2021Joe Ferguson
 
Modern infrastructure as code with ansible PyTN
Modern infrastructure as code with ansible  PyTNModern infrastructure as code with ansible  PyTN
Modern infrastructure as code with ansible PyTNJoe Ferguson
 
Slim PHP when you don't need the kitchen sink
Slim PHP   when you don't need the kitchen sinkSlim PHP   when you don't need the kitchen sink
Slim PHP when you don't need the kitchen sinkJoe Ferguson
 
Throwing Laravel into your Legacy App™
Throwing Laravel into your Legacy App™Throwing Laravel into your Legacy App™
Throwing Laravel into your Legacy App™Joe Ferguson
 
DevSpace Conf 2017 - Making sense of the provisioning circus
DevSpace Conf 2017 - Making sense of the provisioning circusDevSpace Conf 2017 - Making sense of the provisioning circus
DevSpace Conf 2017 - Making sense of the provisioning circusJoe Ferguson
 
Release and-dependency-management memphis python
Release and-dependency-management memphis pythonRelease and-dependency-management memphis python
Release and-dependency-management memphis pythonJoe Ferguson
 
Composer at Scale, Release and Dependency Management
Composer at Scale, Release and Dependency ManagementComposer at Scale, Release and Dependency Management
Composer at Scale, Release and Dependency ManagementJoe Ferguson
 
Put an end to regression with codeception testing
Put an end to regression with codeception testingPut an end to regression with codeception testing
Put an end to regression with codeception testingJoe Ferguson
 
Midwest PHP 2017 DevOps For Small team
Midwest PHP 2017 DevOps For Small teamMidwest PHP 2017 DevOps For Small team
Midwest PHP 2017 DevOps For Small teamJoe Ferguson
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Joe Ferguson
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:winConsole Apps: php artisan forthe:win
Console Apps: php artisan forthe:winJoe Ferguson
 
So You Just Inherited a $Legacy Application… NomadPHP July 2016
So You Just Inherited a $Legacy Application… NomadPHP July 2016So You Just Inherited a $Legacy Application… NomadPHP July 2016
So You Just Inherited a $Legacy Application… NomadPHP July 2016Joe Ferguson
 
So You Just Inherited a $Legacy Application...
So You Just Inherited a $Legacy Application...So You Just Inherited a $Legacy Application...
So You Just Inherited a $Legacy Application...Joe Ferguson
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionJoe Ferguson
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Joe Ferguson
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloudphp[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the CloudJoe Ferguson
 
php[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground Upphp[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground UpJoe Ferguson
 
Madison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small TeamsMadison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small TeamsJoe Ferguson
 
ZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small TeamsZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small TeamsJoe Ferguson
 
ZendCon 2015 - Laravel Forge: Hello World to Hello Production
ZendCon 2015 - Laravel Forge: Hello World to Hello ProductionZendCon 2015 - Laravel Forge: Hello World to Hello Production
ZendCon 2015 - Laravel Forge: Hello World to Hello ProductionJoe Ferguson
 

More from Joe Ferguson (20)

Modern infrastructure as code with ansible cake fest 2021
Modern infrastructure as code with ansible cake fest 2021Modern infrastructure as code with ansible cake fest 2021
Modern infrastructure as code with ansible cake fest 2021
 
Modern infrastructure as code with ansible PyTN
Modern infrastructure as code with ansible  PyTNModern infrastructure as code with ansible  PyTN
Modern infrastructure as code with ansible PyTN
 
Slim PHP when you don't need the kitchen sink
Slim PHP   when you don't need the kitchen sinkSlim PHP   when you don't need the kitchen sink
Slim PHP when you don't need the kitchen sink
 
Throwing Laravel into your Legacy App™
Throwing Laravel into your Legacy App™Throwing Laravel into your Legacy App™
Throwing Laravel into your Legacy App™
 
DevSpace Conf 2017 - Making sense of the provisioning circus
DevSpace Conf 2017 - Making sense of the provisioning circusDevSpace Conf 2017 - Making sense of the provisioning circus
DevSpace Conf 2017 - Making sense of the provisioning circus
 
Release and-dependency-management memphis python
Release and-dependency-management memphis pythonRelease and-dependency-management memphis python
Release and-dependency-management memphis python
 
Composer at Scale, Release and Dependency Management
Composer at Scale, Release and Dependency ManagementComposer at Scale, Release and Dependency Management
Composer at Scale, Release and Dependency Management
 
Put an end to regression with codeception testing
Put an end to regression with codeception testingPut an end to regression with codeception testing
Put an end to regression with codeception testing
 
Midwest PHP 2017 DevOps For Small team
Midwest PHP 2017 DevOps For Small teamMidwest PHP 2017 DevOps For Small team
Midwest PHP 2017 DevOps For Small team
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:win
 
Console Apps: php artisan forthe:win
Console Apps: php artisan forthe:winConsole Apps: php artisan forthe:win
Console Apps: php artisan forthe:win
 
So You Just Inherited a $Legacy Application… NomadPHP July 2016
So You Just Inherited a $Legacy Application… NomadPHP July 2016So You Just Inherited a $Legacy Application… NomadPHP July 2016
So You Just Inherited a $Legacy Application… NomadPHP July 2016
 
So You Just Inherited a $Legacy Application...
So You Just Inherited a $Legacy Application...So You Just Inherited a $Legacy Application...
So You Just Inherited a $Legacy Application...
 
Laravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello ProductionLaravel Forge: Hello World to Hello Production
Laravel Forge: Hello World to Hello Production
 
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016Acceptance & Functional Testing with Codeception - SunshinePHP 2016
Acceptance & Functional Testing with Codeception - SunshinePHP 2016
 
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloudphp[world] 2015 Laravel 5.1: From Homestead to the Cloud
php[world] 2015 Laravel 5.1: From Homestead to the Cloud
 
php[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground Upphp[world] 2015 Training - Laravel from the Ground Up
php[world] 2015 Training - Laravel from the Ground Up
 
Madison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small TeamsMadison PHP 2015 - DevOps For Small Teams
Madison PHP 2015 - DevOps For Small Teams
 
ZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small TeamsZendCon 2015 - DevOps for Small Teams
ZendCon 2015 - DevOps for Small Teams
 
ZendCon 2015 - Laravel Forge: Hello World to Hello Production
ZendCon 2015 - Laravel Forge: Hello World to Hello ProductionZendCon 2015 - Laravel Forge: Hello World to Hello Production
ZendCon 2015 - Laravel Forge: Hello World to Hello Production
 

Recently uploaded

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhisoniya singh
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonetsnaman860154
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 3652toLead Limited
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking MenDelhi Call girls
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slidespraypatel2
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024Scott Keck-Warren
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityPrincipled Technologies
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesSinan KOZAK
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersThousandEyes
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 

Recently uploaded (20)

[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | DelhiFULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
FULL ENJOY 🔝 8264348440 🔝 Call Girls in Diplomatic Enclave | Delhi
 
How to convert PDF to text with Nanonets
How to convert PDF to text with NanonetsHow to convert PDF to text with Nanonets
How to convert PDF to text with Nanonets
 
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
Tech-Forward - Achieving Business Readiness For Copilot in Microsoft 365
 
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
08448380779 Call Girls In Diplomatic Enclave Women Seeking Men
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Slack Application Development 101 Slides
Slack Application Development 101 SlidesSlack Application Development 101 Slides
Slack Application Development 101 Slides
 
SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024SQL Database Design For Developers at php[tek] 2024
SQL Database Design For Developers at php[tek] 2024
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
Boost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivityBoost PC performance: How more available memory can improve productivity
Boost PC performance: How more available memory can improve productivity
 
Unblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen FramesUnblocking The Main Thread Solving ANRs and Frozen Frames
Unblocking The Main Thread Solving ANRs and Frozen Frames
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for PartnersEnhancing Worker Digital Experience: A Hands-on Workshop for Partners
Enhancing Worker Digital Experience: A Hands-on Workshop for Partners
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 

Adventures in Laravel 5 SunshinePHP 2016 Tutorial

  • 1. Adventures in Laravel 5 Joe Ferguson February 4th 2015
  • 2. Who Am I? Joe Ferguson PHP Developer Twitter: @JoePFerguson Organizer of @MemphisPHP @NomadPHP Lightning Talks Passionate about Community
  • 3. Before we begin Have Virtualbox (virtualbox.org) Installed Have VirtualBox Extension Pack Installed Have Vagrant (vagrantup.com) Installed run: vagrant box add laravel/homestead
  • 6. 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
  • 7. 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() !!}
  • 8. 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
  • 9. 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
  • 10. 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 an instance of FormRequest and calls the validate method.
  • 11. 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()
  • 12. Route Caching artisan route:cache Serializes your routes.php Benefits: Faster routing Drawback: Must run artisan route:clear on every routes.php change
  • 13. 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
  • 14. Controller Method Injection Can inject dependencies into methods, no longer via constructor Purpose is to help developers write cleaner code
  • 15. 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
  • 16. 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
  • 17. Socialite Easy to use social logins with oauth Supports Facebook, Twitter, Google, Github, and Bitbucket
  • 18. 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
  • 19. Implicit Route Model Binding Laravel will automatically resolve type-hinted Eloquent model's defined in routes or controller actions whose variable names match a route segment name. Laravel 5.2https://laravel.com/docs/5.2/routing#route-model-binding
  • 20. API Rate Limiting Limit the amount of times a user can access your API with the Throttle middleware. Laravel 5.2https://laracasts.com/series/whats-new-in-laravel-5-2/episodes/2 Will return HTTP Code 429 (Too many requests)
  • 21. Auth & Password Resets New artisan command make:auth generates scaffolding for you. Laravel 5.2https://laracasts.com/series/whats-new-in-laravel-5-2/episodes/3
  • 23. Authentication Drivers Laravel 5.2 Easily have different authentication drivers for multiple authenticatable models or user tables. Useful to allow users from an admins table be able to log in as well as users from a users table.
  • 25. Upgrade from 4.2 to 5.x 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!
  • 26. Upgrade from 4.2 to 5.x https://laravel.com/docs/5.1/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!
  • 27. Quick note on versions 5.1 LTS bug fixes for 2 years, security fixes for 3 years Non LTS: bug fixes for 6 months, security fixes for 1 year 5.1 is currently the only LTS version
  • 28. Which version should you use? 5.2 for my own projects 5.1 for client projects
  • 29. 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!”
  • 30. What’s in the box: • Ubuntu 14.04 • PHP 7.0 • HHVM • Nginx • MySQL • Postgres • Redis • NodeJS • Bower • Grunt • Gulp • Beanstalkd • Memcached • Laravel Envoy Fabric + HipChat Extension + more!
  • 31. Getting Homestead Install the box: vagrant box add laravel/homestead
  • 32. 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.
  • 33. Homestead 2.x & 3.x 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) 3.x will give you PHP 7
  • 34. How I use Homestead
  • 37. Database, Migrations, Seeding database/ factories/ - Default Model Attributes migrations/ - Version control for your DB Schema seeds/ - Sample / Test Data for your DB
  • 42. Time to do stuff!
  • 44. Basic Quick Start https://laravel.com/docs/5.2/quickstart If you already have Vagrant, Run: `./vendor/bin/homestead make` `vagrant up` Run the migration: `php artisan migrate`
  • 48. Exercise 1 Hints Add / edit migration to create users table Add / edit User model Add routes (just like task) Add / edit User Views You can safely disregard any authentication related to users
  • 49. Exercise 1 Solution To see a possible solution checkout the branch “exercise-1” git checkout exercise-1
  • 50. Exercise 2 Assign users to tasks as you create them When listing tasks, show the user they have assigned them When listing users, show how many tasks they have assigned them You can safely disregard any authentication related to users
  • 51. Exercise 2 Hints Add / edit migration to create users table Add / edit User model Add routes (just like task) Add / edit User Views You can safely disregard any authentication related to users
  • 52. Exercise 2 Solution To see a possible solution checkout the branch “exercise-2” git checkout exercise-2
  • 53. Exercise 3 Write Tests for User Functionality Write Tests for Task Functionality
  • 54. Exercise 3 Hints Use Model Factories to seed test data Make sure the task is saved to the DB Make sure the user is saved to the DB Ensure the user delete request succeeds Ensure the task delete request succeeds Ensure the index page loads and contains data You can safely disregard any authentication related to users
  • 55. Exercise 3 Solution To see a possible solution checkout the branch “exercise-3” git checkout exercise-3
  • 58. Exercise 4 Move “Create” Forms to own views Move “Current” html to own views Move Create/Delete User Functionality to Controller method Move Create/Delete Task Functionality to Controller method
  • 59. Exercise 4 Hints Use `php artisan make:controller` to scaffold Utilize your tests to make sure you didn’t break anything: `./vendor/bin/phpunit` You can safely disregard any authentication related to users
  • 60. Using Laravel Facades Using Static Methods: `User::all()` `User::find(1); `User::where(‘user_id`, 1)->get() `User::where(‘email’, ‘joe@joeferguson.me’)->get();
  • 61. Using Dependency Injection Using Injected Object `$this->user->all()` `$this->user->find(1); `$this->user->where(‘user_id`, 1)->get() `$this->user->where(‘email’, ‘joe@joeferguson.me’)->get();
  • 62. Exercise 5 Update your controllers to inject your models instead of using static methods (Facades)
  • 63. Exercise 5 Hints Make sure you “use AppModelName” Utilize your tests to make sure you didn’t break anything: `./vendor/bin/phpunit` You can safely disregard any authentication related to users
  • 64. Exercise 6 Implement index view for tasks Implement index view for users Implement edit functionality for tasks Add tests for your new routes & methods
  • 66. Go forth and develop!
  • 67. Feedback! https://joind.in/talk/f8132 Joe Ferguson Twitter: @JoePFerguson Email: joe@joeferguson.me Freenode: joepferguson Contact Info: