در حال بارگذاری ...

Downloading Example Database0:00

Before we get started, we first need an example database to work with. Let's grab that now. I'll look for mysql-example-db, and if I scroll down, the Sequila database is very common, so we will use that. Here's the installation, we'll grab it here, and if I scroll down, here's the database we can download. OK, next, we can pull this in as a source through terminal, but that's time-consuming and likely doesn't reflect your typical workflow. So instead, I'd recommend pulling in a GUI. SQL Pro on the Mac is great, that's what I use, but you also might take a look at TablePlus,

Creating MySQL GUI Connection1:02

OK, so I'm going to switch over to SQL Pro, and we'll set up a new connection. Now for my system, the username is root, and the password is blank, and that's OK for a local database. So let's test the connection, good, and I will add a new favorite here, and we'll rename it to tutorial. OK, let's go ahead and connect, and we're in. So finally, the only remaining step is to create a brand new database, and again, I'll just call that tutorial. Alright, we're all set to go. So we've set up a MySQL connection, and we've created a database called tutorial.

Importing Schema and Tables1:31

Alright, we're all set to go. So we've set up a MySQL connection, and we've created a database called tutorial. The last step is to import that Sequelize database. So here, we're on that directory I downloaded, so I will begin with the schema. This will set up all of the tables that we need. There we go. So notice lots of things here, like films, and actors, and categories, and payments, and rentals. So lots of things to work with here. However, you'll notice that each of them are empty.

Importing Data and Relationships1:57

So lots of things to work with here. However, you'll notice that each of them are empty. OK, that's the last step. One more time, we will import the data itself. There we go. So really quick, notice that we have actors, and we have films, and we have categories, basically genres of films. And then, to connect these relationships, we can use a linking table, or you might hear it referred to as an associative table. So notice this one associates an actor with a film.

Explaining Associative Tables2:24

it referred to as an associative table. So notice this one associates an Actor with a Film. This table associates a Film with a Category. This is what wires up the connections. So now that we have our example database ready to go, in the next episode, we'll get started with a review of keys.

دوست دارید گاهی خبرهای Laracasts را ایمیل کنیم؟