Upgrading my Laravel 4 App to Laravel 5

I have spent around 20 hours to upgrade one of my medium size, simple Laravel 4 app to Laravel 5, just to note down some of the problem and solutions for this journey.

If you want to switch over to HHVM,  do take note that you will see the blank page often and the easy way to check out the error is checking on the hhvm.log on your homestead vm. I think I spend at least the first 10 hours trying to debug the app without knowing this. Every time I face the blank page error; I just do manual dd in several place to trace the error.

There are two guides you can check on for the upgrade

For the composer.json remember to add in the html and form package, since this 2 package are not longer included in Laravel, and I recommend using the Laravel Collective version

If you are using polymorphic relationship, you will have noticed that unable to update the relationship once you upgrade to Laravel 5. This is due to it only store the model name in Laravel 4, but in Laravel 5 it need to store with namespace, I recommend this solution from StackOverflow rather than update the database

For the Template view

  • take note that now views are under resources.
  • every view now needs to add extends(‘master’) from the master view
  • pagination links not long use the links()  now use render()
  • for the blade tag, instead of change the config to use the old tag I recommend using the new tag.

For Controller

  • remember to add the namespace
  • make use of the method injection, this can avoid load up too many things on the constructor
  • replace the form validation with form request
  • use the helper function like view() , redirect().

Asset Management – if you didn’t use any package for asset management, I highly recommend use Gulp and Laravel Elixer

It’s a little painful to go through so many changes for the upgrade, but I m highly recommend the upgrade and Laravel 5.1 is going to be LTS for 3 year, I believe this worth the effort.

 

You may also like...