This is a small guide on how to migrate a project from Laravel 4 to Laravel 5. This new version has very significant changes and its migration can be somewhat tedious. With these steps that I have compiled, you may save yourself more than one headache.

Steps

Update composer in case you don’t have it updated
composer self-update

Follow the migration instructions in the Laravel documentation

http://laravel.com/docs/5.0/upgrade

When you have followed the steps you will realize that this is only the beginning of the problems, but don’t worry, I have put some points that will clarify your doubts:

 

The NAMESPACES

New functionality is PHP namespaces in Laravel. This will generate conflicts with public classes that you can call or classes that can be implements of base classes in PHP. To do this you should see the examples of WelcomeController.php and User.php to serve as a guide on how to call the namespaces in your php files.

The database configuration

The database connection data is now in a file called .env at the root of the entire project, it will not be necessary to modify the config/database.php file. MySQL is by default.

The classes

For example, if I create a function in controllers that is implements Iterator, in the first lines I must place

uses Iterator

If you don’t do it, it will look for the Iterator class within Laravel (specifically in Controllers) and give an error.

Problem with Eloquent

I have not been able to get the eloquent model calls from Laravel 4 to Laravel 5 to work

So I replaced it with the call DB:: (query Builder)
more info http://laravel.com/docs/5.0/queries

PSR-4

New way to distribute folders in Laravel
Important locations

Routes.php
Laravel4= app/
Laravel5= app/Http/

Controllers folder
Laravel4 = app/controlers
Laravel5 =app/Http/controlers

Views folder
Laravel4= app/views
Laravel5= resources/views

Models folder
Laravel4= app/Models
Laravel 5: no longer exists. The example model user.php is in the root of app.

This doesn’t seem right to me. In the Update documentation they say to take the liberty of creating a Models folder in the app and I have done that and moved Users.php to the Models folder

app/Models

But I have changed the user namespaces
before: namespace App;
now: namespace AppModels;

The Model classes no longer depend on eloquent but on Models
laravel 4: class nombre_de_clase extends Eloquent
laravel 5: class nombre_de_clase extends Model

Blade and Illuminate

Some illuminate functions are no longer included by default in Laravel5. To add some past functions of Illuminate you have to do the following

in config/app.php

in ‘aliases’ add these lines

in ‘providers’ add these lines in the last illuminate

'IlluminateHtmlHtmlServiceProvider',

in composer.json add the following in “require”

then in the console write:
[apache]composer update[/apache] and then
composer dump-autoload

Then go to Blade templates:

replace the {{HTML:: … }} with
{!!HTML:: … !!}

and
{{Form:: … }} to {!!Form:: .. !!}

 

I hope it helps! Don’t forget to share!!!

Previous Post
Say Hi to: Mozilla Firefox Developer Edition
Next Post
Appearance on Hablando TV
ARTÍCULOS RELACIONADOS
No results found.
¿Quieres tranquilidad y rendimiento para tu sitio WordPress?

Optimiza tu web con nuestro servicio de mantenimiento especializado. Deja de preocuparte por caídas, errores y malfuncionamientos.

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.
You need to agree with the terms to proceed

Skip to content