Tags

, , , ,

To get Books of Sanjib Sinha…

To know more about Sanjib Sinha….

Laravel comes with many stunning features. One of them is definitely database migrations. In the next chapter we’ll discuss about migration in detail.
Before that we need to understand our environment properly. What is environment in Laravel? If you look at the document root you will find an ‘.env’ file. It basically says about the database connections. Where would we get that default database set up file? In the ‘config’ folder, we have a ‘database.php’ file. Open it up and see the content.

We see a line that tells us about the default database connection.
//config/database.php
'default' => env('DB_CONNECTION', 'mysql'),

It’s MySQL. We’re not going to change it for now although it’s temporary. Because in the later part of the book we’ll see how we can work with SQLite database. At present just keep it as it is – our default database is MySQL. Now opening up our ‘.env’ file we add our database, username and password.
//.env
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=testdb
DB_USERNAME=root
DB_PASSWORD=pass

There is a glitch of course. Suppose we’d like to place our project in any cloud repository like ‘github’. In that case, our secrets may come out.
Laravel has thought about it.
In the ‘.gitignore’ file it has already added this line:

//.gitignore
/vendor
/node_modules
/public/storage
Homestead.yaml
Homestead.json
.env

When you place the whole project it’ll automatically ignore the listed folders and files. Homestead.yaml and Homestead.json are among them.
We’ve set up our environment and now we can safely move to our next big chapter database migrations. After that we’ll discuss Eloquent and after that we’ll finally see how Model, view and controller workflow work. We’ll also see how we can ‘create, retrieve, update and delete’ our SQLite database.

Advertisements