Automate the Laravel 6 -> 7 Upgrade with PHPStorm
March 15, 2020
Apologies in advance for the slightly click-baity title, but bear with me and this method might prove useful to you. At any rate, I'm documenting it for my own use.
Until the present, I've upgraded 3 of my projects to Laravel 7 and the upgrade times were decent, as summarized in this tweet:
🚀 Manually upgraded 3️⃣ #laravel 6.0 projects → 7.0 over 2 days.— Placebo Domingo (@brbcoding) March 8, 2020
Including deployment, it took:
1st - 54 min - some dependencies caused issues
2nd - 20 min
3rd - 10 min
Right away a pattern emerged: my projects weren't overly complex, and all upgrades followed basically the same path. The hero image at the top summarizes the list of framework files that need to be upgraded. When a 4th project became an upgrade candidate, it got me thinking that I should perhaps automate this to an extent.
PHPStorm has this neat feature that can create a patch from a commit. I've used this many times before, to lift certain diffs and then reapply them somewhere else. I thought, what if I could lift the diffs from one Laravel project, and apply them to another?
Note You might be able to do the same with
git at the command line if you're a Git wizard. I've done it in the past but while I mostly use the command line, for certain tasks I prefer an IDE. Sadly I didn't document the specific commands I used and due to not using them on a regular basis, they've kinda vacated my brain.
So here are the steps I followed to transplant the Laravel 7 upgrade from Project A (previously upgraded to Laravel 7) to Project B (Laravel 6).
- In PHPStorm go to
Version Control > Logfor Project A, select the Laravel 7 upgrade commit (the entire framework upgrade is part of a single commit, in my case)
- Right-click and choose
- Save it to disk
- Open Project B (the project to be upgraded) in PHPStorm
- In the main menu, choose
VCS > Apply Patchand select the
.patchfile created previously
- You'll be presented with the list of files from the commit
composer.lockfrom the file list
routes/web.php, then add
use Illuminate\Support\Facades\Route;manually after. Note You may need to do this for other files in this list where you have custom changes, most notably
At this point the Project B should have been successfully upgraded to Laravel 7.
While it doesn't follow the pure definition of "automation", this technique worked really well for me. Your mileage will obviously vary, and the more complex your project the less likely it will go as smoothly for you.
Here's the file structure in text form, should you need to copy/paste any of it, and happy upgrading!
app/ Exceptions/ Handler.php Http/ Middleware/ VerifyCsrfToken.php Kernel.php config/ app.php cache.php cors.php filesystems.php mail.php queue.php session.php resources/land/en/ passwords.php public/ .htaccess routes/ api.php console.php web.php .env.example composer.json composer.lock phpunit.xml