Would you like to inspect the original subtitles? These are the user uploaded subtitles that are being translated:
1
00:00:00,540 --> 00:00:01,330
Hello again.
2
00:00:01,340 --> 00:00:02,480
My name is Mateo,
3
00:00:02,490 --> 00:00:06,150
and welcome back to the course about Laravel framework fundamentals.
4
00:00:06,540 --> 00:00:11,760
In this module, we'll connect our Laravel app to some SQL database,
5
00:00:11,860 --> 00:00:15,140
but why did I say some SQL database?
6
00:00:15,390 --> 00:00:20,180
Well because it's up to you which database system you will choose to use.
7
00:00:20,250 --> 00:00:24,960
Check out the section in the documentation about getting started with databases.
8
00:00:25,840 --> 00:00:30,090
Here is the list of all currently supported database systems in Laravel.
9
00:00:30,700 --> 00:00:34,970
You can pick any one of these because we'll not work with them directly.
10
00:00:34,980 --> 00:00:37,860
Laravel will provide us with an interface that will
11
00:00:37,860 --> 00:00:39,630
communicate with the database,
12
00:00:39,640 --> 00:00:43,930
instead of us. But before you pick your favorite database system,
13
00:00:43,940 --> 00:00:47,890
make sure that you checked which version of the software is supported.
14
00:00:48,190 --> 00:00:51,930
Since I already have XAMPP installed on my local setup,
15
00:00:51,940 --> 00:00:55,650
I will use the MySQL database that comes with the bundle.
16
00:00:56,040 --> 00:01:02,310
You can do that too, or you can just install MySQL on your system separately.
17
00:01:02,560 --> 00:01:06,150
The most important thing is that you have one of these database
18
00:01:06,150 --> 00:01:09,010
management systems installed on your computer,
19
00:01:09,220 --> 00:01:12,660
but make sure that you know how to install them properly.
20
00:01:12,740 --> 00:01:15,170
If you're not really familiar with that process,
21
00:01:15,170 --> 00:01:18,860
you can install XAMPP like me and follow along.
22
00:01:19,140 --> 00:01:24,450
I can start up the MySQL Server by simply clicking on the Start button.
23
00:01:25,040 --> 00:01:29,290
If you are configuring MySQL and PHP yourself,
24
00:01:29,300 --> 00:01:33,350
don't forget to install the PHP MySQL connector package.
25
00:01:34,240 --> 00:01:39,060
After this is done, we can connect the database to our Laravel application.
26
00:01:39,640 --> 00:01:44,200
Click on the config directory and find the database PHP file.
27
00:01:44,480 --> 00:01:45,360
This is the one.
28
00:01:46,340 --> 00:01:51,050
This file tells our application how to connect to the database.
29
00:01:51,440 --> 00:01:56,520
Here, we can see that the default database system is set to mysql,
30
00:01:56,530 --> 00:02:00,320
and this is only if you didn't specify your own choice in
31
00:02:00,320 --> 00:02:02,960
the DB_CONNECTION environment variable,
32
00:02:03,340 --> 00:02:06,790
but what is this MySQL string referring to?
33
00:02:07,040 --> 00:02:11,160
Scroll down a little bit more to find the connections array.
34
00:02:11,160 --> 00:02:15,260
Each item in this array contains configuration for one
35
00:02:15,260 --> 00:02:17,290
of the supported database systems.
36
00:02:17,290 --> 00:02:22,560
For example, here is the configuration for the default MySQL database,
37
00:02:23,340 --> 00:02:26,790
but notice that the values for these configuration properties
38
00:02:26,800 --> 00:02:30,290
are also taken from the environment variables.
39
00:02:30,370 --> 00:02:33,850
So if you want to connect your application to the database,
40
00:02:33,850 --> 00:02:37,460
you will rarely have a need to change anything in this file.
41
00:02:37,740 --> 00:02:42,130
This is because it's better to get these details from the env file since
42
00:02:42,130 --> 00:02:46,850
that file won't be pushed anywhere publicly like on GitHub,
43
00:02:46,850 --> 00:02:47,550
for example,
44
00:02:47,940 --> 00:02:52,030
and this makes sense because if you push your project to some public repository,
45
00:02:52,030 --> 00:02:55,800
you don't want to have your connection details exposed to the whole world.
46
00:02:55,830 --> 00:02:56,650
Also,
47
00:02:56,660 --> 00:03:01,590
every member of the development team and every environment like production or
48
00:03:01,590 --> 00:03:05,460
testing will usually have different database configuration.
49
00:03:05,740 --> 00:03:08,140
So to set up your database,
50
00:03:08,150 --> 00:03:12,250
usually you will only need to make changes in the env file.
51
00:03:12,640 --> 00:03:16,730
It is placed in the root folder of the project and it contains all of
52
00:03:16,730 --> 00:03:20,170
the environment variables related to our application.
53
00:03:20,470 --> 00:03:23,920
In this lesson, we are only interested in this section.
54
00:03:24,210 --> 00:03:27,500
This is the DB_CONNECTION variable that declares
55
00:03:27,500 --> 00:03:29,860
which database engine will be used.
56
00:03:30,240 --> 00:03:34,100
So if you are using something other than MySQL,
57
00:03:34,110 --> 00:03:35,990
this is where you would change that,
58
00:03:36,000 --> 00:03:41,630
but this value has to be equal to one of the keys from the connections array.
59
00:03:41,860 --> 00:03:45,480
Then we have the database server host, port,
60
00:03:45,490 --> 00:03:49,260
the name of the database, and the credentials for the access.
61
00:03:49,540 --> 00:03:52,280
If you are using XAMPP like me,
62
00:03:52,290 --> 00:03:56,460
these values can be used to connect to the started MySQL Server.
63
00:03:56,840 --> 00:03:59,280
I didn't change any one of the defaults,
64
00:03:59,280 --> 00:04:02,260
but if you did, you can modify them here.
65
00:04:02,640 --> 00:04:07,810
The default host is localhost, the port is 3306,
66
00:04:07,810 --> 00:04:12,400
and the username is root, and this is okay for development purposes.
67
00:04:12,400 --> 00:04:14,640
We don't want to make things more complicated.
68
00:04:14,940 --> 00:04:17,579
You can set any name you want for the database,
69
00:04:17,579 --> 00:04:21,560
but the standard is to give it a name of the project.
70
00:04:21,940 --> 00:04:25,370
Of course, this database doesn't exist yet.
71
00:04:25,380 --> 00:04:30,060
We just have the database system, but we didn't create the blog database,
72
00:04:30,440 --> 00:04:31,550
so let's do that.
73
00:04:31,940 --> 00:04:34,950
It is up to you on how you want to do that.
74
00:04:34,960 --> 00:04:35,840
For example,
75
00:04:35,850 --> 00:04:40,130
you can use the command line interface provided by your specific
76
00:04:40,130 --> 00:04:44,480
database system and run the statement for creating a new database,
77
00:04:44,630 --> 00:04:49,630
or you can install some graphical tool for managing databases and
78
00:04:49,630 --> 00:04:51,350
create the database from there.
79
00:04:51,640 --> 00:04:57,330
If you have XAMPP, that means that you also have access to phpMyAdmin,
80
00:04:57,340 --> 00:05:01,200
which is a web‑based MySQL administration tool.
81
00:05:01,470 --> 00:05:06,660
To use it, we also need to start the Apache Server so make sure that you do that.
82
00:05:07,240 --> 00:05:12,550
In the browser, you can type in localhost/phpmyadmin.
83
00:05:12,940 --> 00:05:15,840
This should open the phpMyAdmin interface,
84
00:05:15,840 --> 00:05:17,860
which should look something like this.
85
00:05:18,240 --> 00:05:22,510
I repeat that you can also use the MySQL command line and
86
00:05:22,510 --> 00:05:25,100
type in the create database statement,
87
00:05:25,110 --> 00:05:27,560
but this is just how I chose to do it here.
88
00:05:27,940 --> 00:05:31,450
I will click on this new link to create a new database.
89
00:05:31,840 --> 00:05:36,000
I just need to provide the database name and click on Create.
90
00:05:36,030 --> 00:05:38,980
This will create a new blog database.
91
00:05:39,020 --> 00:05:42,840
You can now access this new database from the list here,
92
00:05:42,850 --> 00:05:47,650
but as you can see, it's already selected and it's empty,
93
00:05:47,940 --> 00:05:52,180
and this is all we need to do outside of the scope of Laravel.
94
00:05:52,180 --> 00:05:53,980
From this moment on,
95
00:05:53,990 --> 00:05:58,260
we will not do anything with this database directly so make
96
00:05:58,260 --> 00:06:00,820
sure that you installed your database system,
97
00:06:00,820 --> 00:06:06,100
provided its configuration to Laravel, and created a new blog database.
98
00:06:06,340 --> 00:06:11,560
You can check if you did something wrong by running the artisan DB command.
99
00:06:11,840 --> 00:06:16,070
This command will open the cli of the connected database,
100
00:06:16,080 --> 00:06:20,860
so if it works, that means that the connection is successfully established.
101
00:06:21,140 --> 00:06:26,500
In my case, everything seems fine so I will exit the MySQL CLI.
102
00:06:26,500 --> 00:06:30,080
If you get some error or you get nothing at all,
103
00:06:30,090 --> 00:06:32,100
that means that something went wrong.
104
00:06:32,320 --> 00:06:35,070
But don't worry, if this doesn't work,
105
00:06:35,080 --> 00:06:38,860
just follow along until we start running migrations.
106
00:06:39,140 --> 00:06:42,860
You will then get a specific error on why the connection is broken.9313
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.