21.11.2014 Views

Laravel Starter - PHP User Group (Myanmar)

Laravel Starter - PHP User Group (Myanmar)

Laravel Starter - PHP User Group (Myanmar)

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

Quick start: Creating your first web application<br />

<strong>Laravel</strong> <strong>Starter</strong><br />

In this section we'll be building a user administration tool. <strong>User</strong> admins are one of the most<br />

common components to be found in web applications. They also use a number of important<br />

systems that we want to explore with <strong>Laravel</strong> including database interactions, forms, and routing.<br />

We'll be storing and retrieving records from a database so now it would be a good time for you<br />

to create a database for this application. Keep the database name, user, and password handy.<br />

Let's get started.<br />

Step 1 – Database configuration<br />

Armed with our database name, user, and password, we can now tell <strong>Laravel</strong> how to connect<br />

to our database.<br />

Open the file application/config/database.php and scan the contents. You'll find<br />

example configurations for each database driver. Determine which driver you're going to use<br />

from the available options (sqlite, mysql, pgsql, and sqlserv) and enter the name of<br />

the driver as the default database connection.<br />

Then, in the Connections section add your database name, user, and password.<br />

Ok! We're just where we want to be. Let's get started by creating the users table.<br />

Step 2 – Creating the users table using migrations<br />

You might typically create the users table with a tool like phpMyAdmin or Navicat. But, <strong>Laravel</strong><br />

provides a fancy migrations system for us and we should use it because it improves our workflow<br />

and reduces deployment bugs.<br />

Migrations are version control for your schema modifications. Migrations reduce the amount of<br />

headache that we face by requiring us to only define the schema alteration once. Afterwards, we<br />

can deploy our changes to any number of systems without the potential for human error.<br />

Migrations are especially useful for projects in which you're collaborating<br />

with others. Like using source control, migrations are always a good idea.<br />

Developers who are new to migrations might believe them unnecessary or believe that they add<br />

too much additional work at first. But, stick with it and their value will become quickly apparent.<br />

Let's start by creating our migration template with <strong>Laravel</strong>'s command-line tool Artisan.<br />

7

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!