Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranî)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Spanish (Latin American)
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Hello again.
My name is Mateo,
and welcome back to the course about Laravel framework fundamentals.
In this module, we'll connect our Laravel app to some SQL database,
but why did I say some SQL database?
Well because it's up to you which database system you will choose to use.
Check out the section in the documentation about getting started with databases.
Here is the list of all currently supported database systems in Laravel.
You can pick any one of these because we'll not work with them directly.
Laravel will provide us with an interface that will
communicate with the database,
instead of us. But before you pick your favorite database system,
make sure that you checked which version of the software is supported.
Since I already have XAMPP installed on my local setup,
I will use the MySQL database that comes with the bundle.
You can do that too, or you can just install MySQL on your system separately.
The most important thing is that you have one of these database
management systems installed on your computer,
but make sure that you know how to install them properly.
If you're not really familiar with that process,
you can install XAMPP like me and follow along.
I can start up the MySQL Server by simply clicking on the Start button.
If you are configuring MySQL and PHP yourself,
don't forget to install the PHP MySQL connector package.
After this is done, we can connect the database to our Laravel application.
Click on the config directory and find the database PHP file.
This is the one.
This file tells our application how to connect to the database.
Here, we can see that the default database system is set to mysql,
and this is only if you didn't specify your own choice in
the DB_CONNECTION environment variable,
but what is this MySQL string referring to?
Scroll down a little bit more to find the connections array.
Each item in this array contains configuration for one
of the supported database systems.
For example, here is the configuration for the default MySQL database,
but notice that the values for these configuration properties
are also taken from the environment variables.
So if you want to connect your application to the database,
you will rarely have a need to change anything in this file.
This is because it's better to get these details from the env file since
that file won't be pushed anywhere publicly like on GitHub,
for example,
and this makes sense because if you push your project to some public repository,
you don't want to have your connection details exposed to the whole world.
Also,
every member of the development team and every environment like production or
testing will usually have different database configuration.
So to set up your database,
usually you will only need to make changes in the env file.
It is placed in the root folder of the project and it contains all of
the environment variables related to our application.
In this lesson, we are only interested in this section.
This is the DB_CONNECTION variable that declares
which database engine will be used.
So if you are using something other than MySQL,
this is where you would change that,
but this value has to be equal to one of the keys from the connections array.
Then we have the database server host, port,
the name of the database, and the credentials for the access.
If you are using XAMPP like me,
these values can be used to connect to the started MySQL Server.
I didn't change any one of the defaults,
but if you did, you can modify them here.
The default host is localhost, the port is 3306,
and the username is root, and this is okay for development purposes.
We don't want to make things more complicated.
You can set any name you want for the database,
but the standard is to give it a name of the project.
Of course, this database doesn't exist yet.
We just have the database system, but we didn't create the blog database,
so let's do that.
It is up to you on how you want to do that.
For example,
you can use the command line interface provided by your specific
database system and run the statement for creating a new database,
or you can install some graphical tool for managing databases and
create the database from there.
If you have XAMPP, that means that you also have access to phpMyAdmin,
which is a web‑based MySQL administration tool.
To use it, we also need to start the Apache Server so make sure that you do that.
In the browser, you can type in localhost/phpmyadmin.
This should open the phpMyAdmin interface,
which should look something like this.
I repeat that you can also use the MySQL command line and
type in the create database statement,
but this is just how I chose to do it here.
I will click on this new link to create a new database.
I just need to provide the database name and click on Create.
This will create a new blog database.
You can now access this new database from the list here,
but as you can see, it's already selected and it's empty,
and this is all we need to do outside of the scope of Laravel.
From this moment on,
we will not do anything with this database directly so make
sure that you installed your database system,
provided its configuration to Laravel, and created a new blog database.
You can check if you did something wrong by running the artisan DB command.
This command will open the cli of the connected database,
so if it works, that means that the connection is successfully established.
In my case, everything seems fine so I will exit the MySQL CLI.
If you get some error or you get nothing at all,
that means that something went wrong.
But don't worry, if this doesn't work,
just follow along until we start running migrations.
You will then get a specific error on why the connection is broken.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.