In this video, Justin walks you through the major steps in taking your Laravel 5.5 application to Laravel 5.6.
- [Instructor] We'll start with the first step of getting to use the new features in Laravel 5.6. To do this, we're going to upgrade an existing project from Laravel 5.5 to Laravel 5.6. If you're starting with a fresh Laravel 5.6 application, good for you! You'll still want to watch some of this video to get our application started. But afterwards, feel free to jump ahead to the next video. To follow along with our code, we're going to look in our exercise folder for this lesson.
There's a folder labeled community-poll. This is a sample project we'll use to work in. If you followed my earlier course on building RESTful APIs with Laravel, this codebase should look pretty familiar. To begin, we'll either keep the code here in the exercise folder, or we'll move it somewhere where we'll be working on our project. In this case, I'm going to put it in my documents folder. Feel free to move it anywhere that you want to however.
Once there, you'll want to find the absolute path to the community-poll directory. If you know how to use a terminal application, you can open your terminal application to this directory, and use the command pwd on Mac OS and Linux to get the path, and on Windows you use the command cd. We're going to copy this path. And then we're going to open up the .env file in the community-poll directory with our text editor.
We want to use this path to prefix the DB_DATABASE value on line 11. You're going to want to be sure to include the file path separator at the end before the database.sqlite. On Windows, the file path separator is a backslash. And on Mac OS and Linux, it is a forward slash. So your line 11 should read DB_DATABASE equals our file path, the appropriate slash, and then database.sqlite.
Let's verify our application is working real fast. We'll save this file. We'll go back to our terminal application. And we'll run the command php artisan serve. This should start up our server at http://127.0.0.1:8000. This colon 8000 is a port number. If we copy this and open up a browser window, and paste it in, and go to our URL, we should see the Laravel homepage.
Now if we visit that URL in api/polls, we should see a JSON array presented to us. This is a listing of polls. Our application has some fairly basic API endpoints for us. At this point, we can bring down the application. Go back to our terminal application, and use the command control + C to end it. Now we want open up the composer.json file in our text editor of choice.
The composer.json file is the file that Composer uses to define the dependencies for our application. Since we're upgrading our application from Laravel 5.5 to Laravel 5.6, this is where we're going to edit all of those dependencies. First thing that we're going to do, is we're going to update the laravel/framework version on line 10 from 5.5 to 5.6. The next thing that we'll do is we'll update the fideloper/proxy version from 3.3 to 4.0.
The last thing we need to do is update the phpunit dependency, which is on line 17 to 7.0. Save your updated composer.json file. And now run the command composer update. Now that Composer has updated all of our dependencies, we can run php artisan serve one more time, and verify that our application is working correctly.
Again, we'll go back to our browser and refresh the page. And it seems like there's a little bit of an error here. And that's okay, this is expected. We need to upgrade one other little thing. We'll go back to our text editor, and open up the file at app/Http/Middleware/TrustProxies.php. And on line 22, we want to replace that array of headers with just the line, Request::HEADER_X_FORWARDED_ALL.
That was Request::HEADER_X_FORWARDED_ALL. We'll save this, go back to our browser, and refresh the page. And there we go, everything's working again. Notice how easy it was to upgrade to Laravel 5.6. For this particular application, it's fairly small and compact. So we didn't have to change much. However, for your particular application, you may have to change other parts of your codebase. If you have tests, your tests should be able to help you identify any places where you need to make changes.
Otherwise, this course as well should also give you a good understanding of the different areas of Laravel that have changed, and where you might have to change parts of your particular application. The Laravel documentation also provides, as normal, an upgrade guide noting any places where you can expect breaking changes.