jonaspas's avatar

How to upgrade to Laravel 5.3?

Hi there, I'm sorry, this is probably a foolish question... but... how do I upgrade my laravel installation to 5.3 (from 5.2)? I know, there's the upgrade guide (https://laravel.com/docs/5.3/upgrade#upgrade-5.3.0) but it seems I'm missing something. Where do all the new files come from (like the new route-files)? In the upgrade-guide for 5.2 it says in the beginning that I should update my composer.json file. So I did this also for 5.3. Then I ran composer update, but then I get the following error: "PHP Fatal error: Uncaught Error: Call to undefined method Illuminate\Support\Facades\Auth::user() in /opt/lampp/htdocs/myproject/vendor/laravel/framework/src/Illuminate/Support/Facades/Facade.php:238".

How is the official way to upgrade Laravel to 5.3?

Thanks in advance Jonas

0 likes
26 replies
davorminchorov's avatar

Follow the guide first, make all of the changes that are needed and after you are done with it, run composer update.

4 likes
jonaspas's avatar

Ok @Ruffles, thank you, I will try this. But why isn't this in the docs?

2 likes
davorminchorov's avatar

I am guessing, it's common sense. You can add it yourself or ask on the github repo for the docs.

1 like
davorminchorov's avatar

Oh and I forgot, the new routes setup is coming from the folder structure that comes with laravel when you download a new project. You don't need to upgrade that part as far as I know, but if you want to, you can copy the RouteServiceProvider.php and routes folder from github and it should work.

1 like
davidlapham's avatar

Is the composer update supposed to pull in the new files (e.g. new routes folder)?

bestmomo's avatar
bestmomo
Best Answer
Level 52

I think that for a 5.3 upgrade it's better to install a fresh Laravel and copy application inside it. It's more work but avoid many issues.

9 likes
bugsysha's avatar

That is why I keep all my code inside packages or specific folders with service providers.

bugsysha's avatar

Always. Or as the song about Ernesto Che Guevara would say "Hasta Siempre" :P

Ili bolje da me razumes, zajebes se ako ne radis tako :D

Sorry guys about non english part. Internal joke :)

1 like
richard@gorbutt.com's avatar

I'll second or third the @bestmomo answer. I've tried 5.0 to 5.1 and 5.1 to 5.2 and just found it way less aggro to perform a new install and then reverse the old app into the new structure. I recall trying 5.1 to 5.2 just kept giving me problems, stuff that I could fix with answers here but were not in the upgrade guide. I finally gave up and did a clean install and added the old app. That took less than 30 mins for me.

ejdelmonico's avatar

I installed a fresh copy and modified what was necessary. I had to change a bunch of my tests as well so the fresh install made it less of a hassle...just a bit more work.

davorminchorov's avatar

When I upgraded a small project, it took me about 15-20 minutes, I just followed the guide and it worked fine. Now, it really depends how big the project is, I didn't have to change half of the things in the upgrade guide.

jason-mccreary's avatar

While all the answers here are helpful, as the creator of Laravel Shift I want to point out a few things.

While the Laravel Upgrade Guide is a tremendous resource, it is not exhaustive. There are plenty of changes between versions that are not listed. While most of these changes are admittedly small and may not matter to the current upgrade, they likely will matter in future versions.

So, simply following the Upgrade Guide, especially just picking and choosing changes from the Upgrade Guide is not a very thorough way to upgrade your application.

If you are going to upgrade manually and your application is small enough, I agree that dropping your files into a new Laravel application is a better upgrade process in general. However, this is also the most time consuming approach.

All these reasons and more are why I created a service to automate the process of upgrading your Laravel applications.

3 likes
spekkionu's avatar

The upgrade guide covers the things you need to to get your app running again on the new version but there are many changes that are optional.

For example the directory changes and the changes to the routes files are not required to be changed for the upgrade. Your app can run just fine using the 5.3 framework libraries but the 5.2 directory structure.

If keeping the old directory structure doesn't bother you, you can just leave it or you can make the changes. This will require a bunch of manual work and comparing files in your app with the ones in the laravel/laravel repository and merging in the differences. If you have made customizations to any of these files you will have to merge your changes with the new version. The upgrade guide does not cover these changes as they are not required. Having done this before I can say this isn't a very fun process and is easy to miss things.

I have heard good things about Laravel Shift but haven't used it myself. It likely makes the process much easier. At the very least it should reduce the changes of forgetting something.

2 likes
Mithridates's avatar

@bestmomo I have a Laravel 5.1 app, if I create a new 5.3 project and copy all my files, what will happen to my git files. can explain a bit how you would approach it?

1 like
bestmomo's avatar

@Mithridates

If you install a fresh 5.3 version you wont have something working directly by copying all files from a 5.1 version because there are many changes.

You can copy without big issues resources, database, config, form requests, middlewares...

For controllers there are some changes for authentication. Routes are in another folder with different web middleware.

I dont understand what you mean with your git files...

Mithridates's avatar

@bestmomo you mentioned in previous answers that One could just create a fresh install of laravel 5.3 and copy all files from 5.1 to 5.3. I'm just wondering how can I upgrade my 5.1 app to 5.3 with ease?

davorminchorov's avatar

I still think that for small projects which don't use every possible feature, it's better to just follow the docs. I upgraded 2 projects so far and it took me 15-20 minutes with the composer update part included.

You could install a fresh copy of the framework but you'll still need to copy over files and set it up, which might end up taking more time than following the upgrade guide.

bestmomo's avatar

@Mithridates

When I say to copy files I mean also make somes changes to get them working in new environment.

So you have the choice :

  • follow the upgrade guide from your 5.1 version
  • install a fresh 5.3, copy your application and also follow the upgrade guide to make the changes

I think there are few issues with the second method.

1 like
zanematthew's avatar

Why its this hard, (or not as well documented) is beyond me. All I had to do is mentioned in the section; "Application Service Providers"

You may remove the arguments from the boot method on the EventServiceProvider, RouteServiceProvider, and AuthServiceProvider classes. Any calls to the given arguments may be converted to use the equivalent facade instead. So, for example, instead of calling methods on the $dispatcher argument, you may simply call the Event facade. Likewise, instead of making method calls to the $router argument, you may make calls to the Route facade, and instead of making method calls to the $gate argument, you may make calls to the Gate facade.

~However I do have an existing Spark application that is being troublesome to update.~

Correction, just as mentioned in the upgrade page:

The AuthorizesResources Trait The AuthorizesResources trait has been merged with the AuthorizesRequests trait. You should remove the > AuthorizesResources trait from your app/Http/Controllers/Controller.php file.

My only gripe is that the steps are not clearly labeled, however this is probably intentional.

willvincent's avatar

Definitely agree with @bestmomo's advice on this. I upgraded a project from 5.1 to 5.2, and had to take several passes with a fine-toothed comb to catch all the little changes I'd missed.

wayand's avatar

HI. upgrading to 5.3, what to do first: make changes to app code and then make changes to composer.json and run composer update ? or

make changes to composer.json and run composer update ? and then make chenges to your app code?

-- i did the first one, and got this Error:

[ErrorException]
  Declaration of App\Providers\EventServiceProvider::boot() should be compatible with Illuminate\Foundation\Support\Providers\EventServiceProvider::boot(Illuminate\Contracts\Events\Dispatcher $events)


´´´
pmall's avatar

Usually for upgrade I create a new project with the version I want, and I copy the .git folder of my current project inside it. This way I can keep track of all missing/updated files. I copy files and check those which has been modified until I got everything right.

connor11528's avatar

So what if we have a massive laravel application? We're supposed to do "laravel new" and copy every single file into a new project. What about version control? It's suprising to me the solution is brand new project!

The alternative I gues would be to update composer.json and see what breaks

Please or to participate in this conversation.