Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Upgrading a Laravel 4 Application to Laravel 5

Upgrading a Laravel 4 Application to Laravel 5

Given as a Nomad PHP Lightning Talk - 2015-03-19

From this blog post:

https://mattstauffer.co/blog/upgrading-from-laravel-4-to-laravel-5

Matt Stauffer

March 19, 2015
Tweet

More Decks by Matt Stauffer

Other Decks in Technology

Transcript

  1. 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
  2. Git Caveat If you want to maintain file consistency, either

    don't commit along the way, or squash at the end
  3. 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
  4. 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
  5. Running this: php artisan app:name SaveMyProposals Takes us from: <?php

    namespace App\Http\Controllers; to: <?php namespace SaveMyProposals\Http\Controllers;
  6. 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.
  7. Step 7.f If you're still using app/models, add it to

    composer.json: "autoload": { "classmap": [ "database", "app/models" ] }
  8. 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'])
  9. Step 7.h Move any bindings you registered in start/global.php to

    app/Providers/AppServiceProvider@register()
  10. 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
  11. Step 10 Update auth (User) model The fastest way is

    to use the new User model. If not, read the instructions.
  12. Change {{ and }} to {!! and !!} anywhere you

    need un-escaped echo OR // In AppServiceProvider@register(): \Blade::setRawTags('{{', '}}'); \Blade::setContentTags('{{{', '}}}'); \Blade::setEscapedContentTags('{{{', '}}}');
  13. 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.
  14. Delete every file out of the new public directory except

    index.php, and move your old files in.
  15. 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