Playing
02. Setting up the example project

Transcript

00:00
Following along with this course is, of course, optional, but if you do want to, we have an example project in the download section which you can grab and set up ready to follow with every single episode.
00:11
So in this video, if you are new, I'm just going to show you how to set this up once you have it downloaded and running on a web server. So if you do have it running on a web server right now, you'll probably see something like this. That's because we haven't included any of the composer dependencies or anything like that. So let's go ahead and just get started with that.
00:31
We're going to, first of all, do a composer install within the main directory here. That's going to go ahead and just pull all of our dependencies down. What we're also going to do is an npm install as well. So let's run that, too, just to put in all of the dependencies for our front end.
00:46
And once you've done that, you're going to want to run and leave running npm run dev. So if we head over now and just give that a refresh, you can see that, sure enough, we have progressed a little bit. Next step is to go ahead and create our database called Laravel underscore performance. And of course, if you have worked with Laravel before, you know that you can tweak that just over here.
01:08
And of course, you're also going to want to update all of your database settings in here as well. So I'm running Postgres, but if you're using MySQL, that is absolutely fine. Next step in that case is to run PHP artisan migrate just to create out all of the base tables that we need, including posts and users, which are the main two things we're going to be working with.
01:28
And that should give you something like this. Now, this first page here, as we saw from the introduction, is just a list of articles. So in this case, we want to generate out some fake data. Now, as part of this example project, if we just head over to the database section here,
01:46
we have a blog seeder already created, or you can do this on the command line using Laravel Tinker. So what this is going to do is use the default user factory, which exists over in the factory just here. So that gives us a fake list of all of the attributes that a particular user can have. And it will create five users and they have 100 posts each.
02:11
So if we just take a look into the user model, you can see that the relationship here is already set up to the post model. And this has 100 each and we just create them simple as it is using Laravel factories. So to actually generate out this data, we're going to go ahead and run PHP artisan db seed. And we're going to choose the name of the seeder. In this case, it's blog seeder.
02:34
Give that a few seconds to run and you should have a load of data in your database. You can see here, of course, we've got 500 articles because we have 10 users with 100 posts each. Aside from that, there's not really much to do. So we're going to head over to the next episode where we're going to analyze this page using Laravel debug bar.

Episode summary

In this episode, we're getting everything ready to follow along with the course's example project. If you want to code along, you'll first need to download the project files from the downloads section. Once you've got the files and popped them onto your web server, you'll probably notice things aren't working just yet—no worries, that's normal.

The first step is to get our backend dependencies set up. We do that by running composer install in the project directory. Next, we handle the frontend dependencies with npm install. After that's done, start up the frontend watcher with npm run dev so any changes you make later will be instantly reflected.

With the dependencies sorted, it's time to set up the database. You'll need to create a database (the guide uses laravel_performance as an example) and update your .env file with the right database settings—doesn't matter if you're using Postgres or MySQL. Then, migrate the database tables using php artisan migrate.

To get some actual data to work with, we seed the database using an existing blog seeder. This creates a bunch of users and posts using Laravel's factories, so your project will have hundreds of fake articles to play with. You'll use php artisan db:seed --class=BlogSeeder to make this happen.

Once all that's done, you should see a list of articles when you reload the app in your browser. We're all set up now, and in the next episode, we'll dive into analyzing this page using Laravel Debug Bar!

Episode discussion

No comments, yet. Be the first!