Post
  • application
  • files
  • FTP
  • Laravel
  • update
  • upgrade
  • web development
  • website

How to Upgrade Laravel 4 application to 5

Learn how to upgrade Laravel 4 application to latest version Laravel 5.4. This is a technicle article very beneficial for your web application security. Changes to composer, MVC and core Laravel.

   
How to Upgrade Laravel 4 application to 5

The Right Software are a Laravel development company. Our clients have working Laravel 4 and Laravel 5 web applications and we always suggest them to upgrade Laravel 3 and Laravel 4 at the earliest possible. However, Laravel 5 is a major release and thus needs to be handled with care so as to not break the production application.

Here we provide a handy list of steps to upgrade Laravel 4 application to latest version Laravel 5.4 framework.

How to upgrade Laravel 4 to 5

Current version (at the time of this article) of Laravel framework is 5.4. There are many apps written in Laravel 4 that need to upgraded to latest Laravel 5 version. In this tutorial, we will explain on how to upgrade Laravel 4 web application to latest laravel 5. So following are the most common steps to be taken in order to upgrade from Laravel 4 to Laravel 5.

 

General Note

Please bear in mind that these are technical steps and important that a professional programmer handles these tasks. These are not for webmasters. Please also note that we do not discuss your application logic or innards. Do these steps on a separate installation and then port your DNS onto new setup or push code from new remote to production environment.

Fresh Installation

Setup a staging area and install a fresh copy of Laravel 5.x application. This can be done via composer by executing the following command.

composer create-project laravel/laravel –prefer-dist

Composer is the PHP package/dependency manager. You can read more about Laravel 5 installation in Laravel official documentation.

 

Configuration Files

In Laravel 4, the configurations files are kept in the app/config folder while in Laravel 5, config folder is placed outside of the app i.e. on the root level. So copy all your configuration files like database.php, auth.php, mail.php etc from app/config to config.

 

Routing

Routes are registered in app/routes.php in Laravel 4 while in Laravel 5 anything related to HTTP is grouped inside app/http folder. So move routes.php file from app to app/http folder

Filters are changed to middlewares in Laravel 5. So if you have any filters in the routes.php change them to middlewares.

 

Controllers

As controllers are also part of the HTTP logic. Therefore move it from app/controllers to app/Http/Controllers and namespace them with app/Http/Controllers. Also change BaseController to Controller class.

 

Models

In Laravel 4, models are placed in the model folder. In Laravel 5, model folder is removed and thus models are stored directly in the app folder. So copy your models from model folder to app folder.

 

Views

Copy all the views from app/views to resources/views folder.  The resources folder also contains assets for application front-end assets as well as the lang folder for localization of the application.

 

Migrations

Copy all the migrations files from app/database folder to database folder. This folder already contains a users and a password_resets table which you may want to delete or update depending upon your needs.

 

Composer

Copy all the composer dependencies of the application to the new composer.json file and run composer update command to reflect the changes.

 

Forms and HTML

In Laravel 5, the illuminate/html package is removed from the default installation and will need to install it separately.

In order to bring HTML helpers back to your project, you will need to add “illuminate/html”: “5.0.*” package to composer.json file and run composer update. Then add ‘Illuminate/Html/HtmlServiceProvider’ to config/app.php providers array. To use Html and Form facades inside blade templates, includes the following facades to config/app.php facades array.

‘aliases’ => [
    ...
    ....
    ‘html’=> ‘Illuminate/Html/HtmlFacade’,
    ‘form’=> ‘Illuminate/Html/FormFacade,
    ...
],

 

Conclusion

So in this article we have explained the most common changes required for upgrading from Laravel 4 to 5. Depending on your application size, there may be more or less complexities encountered in the upgradation process. You can read more about upgrading from Laravel 4 to Laravel 5 on the Laravel official documentation.

If you are unsure of any steps then contact us for free consultation . You can hire Laravel deveopers with us. We’ll be glad to upgrade it for you.