Slide 1

Slide 1 text

Upgrading a Laravel 4 application to Laravel 5

Slide 2

Slide 2 text

Wherefore? Major framework version upgrades: Thoughtbot, Rails 2->3 Large app, 2 devs, 1 month Laravel 4->5 is a few hours to a day, depending on the app. But, it’s not drag-and-drop

Slide 3

Slide 3 text

Today’s Guinea Pig: SaveMyProposals

Slide 4

Slide 4 text

(Check it out on Github later) github.com/mattstauffer/savemyproposals

Slide 5

Slide 5 text

Caveat Do the minimum viable upgrade.

Slide 6

Slide 6 text

Git Caveat If you want to maintain file consistency, either don't commit along the way, or squash at the end

Slide 7

Slide 7 text

Step 1 Branch your app and nuke the files

Slide 8

Slide 8 text

cd Sites/savemyproposals-original-site git checkout -b laravel-5-upgrade rm -rf * rm .gitattributes rm .gitignore rm .travis.yml/etc.

Slide 9

Slide 9 text

Step 2 Install Laravel 5 fresh into the new branch

Slide 10

Slide 10 text

git remote add laravel https://github.com/laravel/laravel.git git fetch laravel git merge laravel/master --squash git add . git commit -am "Bring in Laravel 5 base." composer install

Slide 11

Slide 11 text

Step 3 Clone old site parallel

Slide 12

Slide 12 text

git clone git:giturl.git ../savemyproposals-temp-clone So we have two folders parallel: ls .. Total 123 drwxr-xr-x 1 usr staff 748 Jan 1 2015 savemyproposals-temp-clone drwxr-xr-x 1 usr staff 748 Jan 1 2012 savemyproposals-original-site

Slide 13

Slide 13 text

Step 4 Set your domain namespace (optionally)

Slide 14

Slide 14 text

Running this: php artisan app:name SaveMyProposals Takes us from:

Slide 15

Slide 15 text

Step 5 Migrate your Composer dependencies

Slide 16

Slide 16 text

Easiest option: copy your dependencies over to the new composer.json. Then composer update.

Slide 17

Slide 17 text

Step 6 Move your primary domain folder

Slide 18

Slide 18 text

cp -r ../savemyproposals-temp-clone/src ./app Or, in a GUI, copy all the files from your old domain folder (e.g. /src or /app/YourProjectName) into the app folder (/app). /app Console/Commands/etc. Http/Controllers/etc. Your/Domain/Folders/etc.

Slide 19

Slide 19 text

Step 7 Move your framework-specific code

Slide 20

Slide 20 text

Step 7.a Move commands from app/commands to app/Console/Commands

Slide 21

Slide 21 text

Step 7.b Move controllers from app/controllers to app/Http/Controllers

Slide 22

Slide 22 text

Step 7.c Move database from app/database to database

Slide 23

Slide 23 text

Step 7.d Move filters from app/filters.php to app/Providers/RouteServiceProvider.php@boot()

Slide 24

Slide 24 text

Step 7.e Move language files from app/lang to resources/lang

Slide 25

Slide 25 text

Step 7.f If you're still using app/models, add it to composer.json: "autoload": { "classmap": [ "database", "app/models" ] }

Slide 26

Slide 26 text

Step 7.g Move routes from app/routes.php to app/Http/routes.php *Note: Adjust built-in filter calls (e.g. ['before' => 'auth']) to be middleware calls (e.g. ['middleware' => 'auth'])

Slide 27

Slide 27 text

Step 7.h Move any bindings you registered in start/global.php to app/Providers/AppServiceProvider@register()

Slide 28

Slide 28 text

Step 7.i Move tests from app/tests to tests

Slide 29

Slide 29 text

Step 8 Migrate your configuration

Slide 30

Slide 30 text

4 Shift your mentality (no environment folders) 4 Move over your keys into .env.example 4 Copy .env.example to .env and move over your values 4 Learn APP_ENV, APP_DEBUG, APP_KEY, DB_*, *_DRIVER

Slide 31

Slide 31 text

Step 9 Move any loose files-- readme.md, .travis.yml, etc.-- into the new branch

Slide 32

Slide 32 text

Step 10 Update auth (User) model The fastest way is to use the new User model. If not, read the instructions.

Slide 33

Slide 33 text

Step 11 Update your Blade echo syntax

Slide 34

Slide 34 text

Change {{ and }} to {!! and !!} anywhere you need un-escaped echo OR // In AppServiceProvider@register(): \Blade::setRawTags('{{', '}}'); \Blade::setContentTags('{{{', '}}}'); \Blade::setEscapedContentTags('{{{', '}}}');

Slide 35

Slide 35 text

Step 12 Configure Laravel

Slide 36

Slide 36 text

Inform Laravel that your controllers have no namespace: // app/providers/RouteServiceProvider protected $namespace = null; Add the controllers and commands directories to the composer.json classmate autoload if you're not namespacing them.

Slide 37

Slide 37 text

Step 13 Move public files

Slide 38

Slide 38 text

Delete every file out of the new public directory except index.php, and move your old files in.

Slide 39

Slide 39 text

Step 14 Update application code with API changes

Slide 40

Slide 40 text

Just a few API changes: 4 SoftDeletingTrait on models is now SoftDeletes 4 No more Eloquent remember()--cache manually 4 Replace $paginator->links() with $paginator- >render() 4 Update Composer dependency pda/pheanstalk~2.1 to pda/pheanstalk~3.0

Slide 41

Slide 41 text

Step 15 CSRF Routing Disable middleware in app/Http/Kernel or set form field _token to value csrf_token()

Slide 42

Slide 42 text

Step 16 HTML & Forms (optionally) github.com/laravelcollective

Slide 43

Slide 43 text

Step 17 Bringing Whoops Back (optionally) mattstauffer.co/blog/bringing-whoops-back-to-laravel-5

Slide 44

Slide 44 text

Step 18 Check the upgrade guide: http://laravel.com/docs/5.0/upgrade

Slide 45

Slide 45 text

Thanks! https://joind.in/14291 @stauffermatt mattstauffer.co