Laravel4 Migrations and Seeding

So far we have created the virtual host for our laravel4 application named “” and also set up the basic laravel4 installation. Now in this lesson we will create the migrations and seeders needed for our application.

“Migrations are a type of version control for your database. They allow a team to modify the database schema and stay up to date on the current schema state. Migrations are typically paired with the Schema Builder to easily manage your application’s scheme.”

“Laravel also includes a simple way to seed your database with test data using seed classes.”

First thing first. Open up the Mac Terminal and enter inside the “thisdayinbangladesh” folder under MAMP’s “htdocs” directory. All of the following commands should be executed from inside the project folder.

Create migration files for all of our currently needed tables:
Execute these commands one by one,

These commands set up the basic migration scripts that we’ll be using to create the database tables

Update the migration files:
Edit “database/migrations/TODAYS_FULL_DATE_create_days_table.php” file and update the “up()” method to include a new column on the “days” table and to remove the “timestamp” column.

Update the “up()” method of “database/migrations/TODAYS_FULL_DATE_create_facts_table.php” file to the following,

Update the “up()” method of “database/migrations/TODAYS_FULL_DATE_create_types_table.php” file to the following,

Update the “up()” method of “database/migrations/TODAYS_FULL_DATE_create_fact_type_table.php” file to the following,

Prepare the Seeder files to add sample data to those tables:
Create a file within the “app/database/seeds” folder that has the same name as the table. So, for our “days” table create a file named “DayTableSeeder.php” inside “seeds” folder containing the following full code,

Here I am inserting some “day-month” patterned days rows in the “days” table using a simple loop. Please, don’t judge my PHP knowledge on this. This is not about showing optimized, minimal, smell free coding.
Also, create other seeder files for those remaining tables into which we want to push some sample data even before launching the app.
Create “FactTableSeeder.php” with following code. Here we are inserting some sample facts that holds the fact’s sample title and sample description just for checking out data retrieval with proper relations later on the next lesson.

Now create the “TypeTableSeeder.php” file with the following code,

And finally create the “FactTypeTableSeeder.php” file with,

As you can see, we are assigning some “facts” to some “types” and making rows in the “fact_type” table pairing “fact_id” with “type_id” as for our sample data.

Update the DatabaseSeeder file:
Update the “run()” method of the “DatabaseSeeder.php” file. That should already be there inside “app/database/seeds” folder with the following code,

Run Migration and Seed:
Execute the following commands one by one.

If the commands executed successfully then you should see those tables along with an extra tables named “migrations” under your “thisdayinbangladesh” database. Also there should be our sample data in each table if the Seeding happens successfully!

As one “fact” will have multiple “types” and vise versa. You should name the Pivot table (“fact_type” in this case) of the “facts” and “types” table by taking the singular name of the alphabetically first table then the second table with an underscore in the middle.
Also there should be two columns at least, to hold the relation which should be named by taking the singular name of one table with its primary key along with an underscore in the middle. Such as “fact_id”, “type_id”.
But wait, don’t be scared. There is still flexibility while naming those tables and columns for using with Eloquent ORM. You will have to just pass those non-conventional table names or column names as parameters in corresponding methods while creating ORM relations among tables or while creating migrations tables.
We just followed the conventional naming pattern in this lesson to make thing simple and understandable.

What next?:
The next step is to make proper Routing for our application. Which is ready now!

Installing Laravel4 in Mac OSX with MAMP

In the past and first tutorial of this series we learned how to create a virtual host with MAMP. In this second tutorial, we will install laravel4 PHP framework and will go another step toward developing a full laravel4 application series.


  • Make sure your installed PHP version is greater or equal to 5.3.7
  • Also make sure the MCrypt PHP extension is enabled
  • For pretty URL the mod_rewrite module is enabled on Apache

1. Install Composer Globally:

The following command will just check a few PHP settings and then download composer.phar

You can run these commands to easily access composer from anywhere on your system

2. Create a laravel project named “thisdayinbangladesh” inside our MAMP’s “htdocs” directory:

Going inside the “htdocs” directory

Creating the project there

3. A small permission issue:

Lets enter into our project directory

Change the permission of the storage folder to writable

4. Basic Configuration:

Update line number 29 of the “app/config/app.php” file to

and line 42 to

5. Database configuration:
Though configuring database is not necessary to have a first run but lets complete this step as we will not do any editing on the config files later.

6. Lets have a test run:

Open the URL of your laravel application as we created earlier using virtual host; on the browser. That is
You should arrive!

How to Set Up Virtual Host with MAMP on a Mac OSX

1. Update the hosts file:
We are going to add an example domain named “” as a virtual host through this tutorial. Lets first add this in the “hosts” file by typing the following command on the Terminal,
[sourcecode lang=”bash”]sudo nano /etc/hosts[/sourcecode]
Then find the following line,
[sourcecode lang=”bash”] localhost[/sourcecode]
update this to following,
[sourcecode lang=”bash”] localhost[/sourcecode]
Also to add our domain to the IPv6 version find the following line somewhere bottom of the file,
[sourcecode lang=”bash”]fe80::1%lo0 localhost[/sourcecode]
update this line to the following one,
[sourcecode lang=”bash”]fe80::1%lo0 localhost[/sourcecode]
Finally press “ctrl+x” and then “y” to save and exit this file.

2. Update httpd.conf file
Open up this file by typing the following command,
[sourcecode lang=”bash”]sudo nano /Applications/MAMP/conf/apache/httpd.conf[/sourcecode]
find out the following line,
[sourcecode lang=”bash”]#Include /Applications/MAMP/conf/apache/extra/httpd-vhosts.conf[/sourcecode]
It might have a “#” symbol at the very beginning of the line. Delete the symbol to activate this statement. If the line is not anywhere of the “httpd.conf” file then add the above line anywhere of this file. Now, save and exit this file.

3. Update httpd-vhosts.conf file
Now go into the “/Applications/MAMP/conf/apache/” folder by executing,
[sourcecode lang=”bash”]cd /Applications/MAMP/conf/apache/[/sourcecode]
If you can see a folder named “extra” then enter inside it otherwise create this “extra” folder and then enter inside it.
Now update (If there was already a “extra” folder then there should be a “httpd-vhosts.conf” file other wise just create the “httpd-vhosts.conf” file inside “extra” folder) the “httpd-vhosts.conf” file by typing the following,
[sourcecode lang=”bash”]sudo nano httpd-vhosts.conf[/sourcecode]
Then the final “httpd-vhosts.conf” file should have the following code block. Whether you add these lines or updated the existing file.
[sourcecode lang=”bash”]
NameVirtualHost *:80

DocumentRoot "/Applications/MAMP/htdocs"

<VirtualHost *:80>
DocumentRoot "/Applications/MAMP/htdocs/thisdayinbangladesh/public"
<Directory "/Applications/MAMP/htdocs/thisdayinbangladesh/public">
Options All
AllowOverride All
Order allow,deny
Allow from all
Here “thisdayinbangladesh” is a project directory; actually a laravel4 project directory inside my “htdocs” folder and we added the “public” folder thats resides in “thisdayinbangladesh” folder as the document root cause laravel4 needs to point to the “public” folder as the application root URL.
In this stage of this example. You can forget about laravel4 and simply create the directory “/thisdayinbangladesh/public” inside your “htdocs” folder and place a simple “index.html” file there inside the “public” folder.

4. Restart:
Simply stop and re-start the Apache service from your MAMP control panel. Then try out the URL on your browser. You should see your “index.html” file!

This tutorial will take you through out a nice series of posts on which a full laravel4 web application has been developed. That service is already LIVE HERE. So, stay tuned!

The next tutorial is ready Installing Laravel4 in Mac OSX with MAMP. So, you are another step close toward the full laravel4 application development series.

A jQuery Plugin Snippet for Sublime Text 2

You can simply (yes really simply) create a code snippet on Sublime Text 2 for faster code completion by clicking on the Tools -> New Snippet  menu of sublime and by editing the snippet template according to your choice.
You will have to edit/update line number 3 to the code block you want to have while calling the snippet by a shortcode. Uncomment line 6 & define a shortcode typing which you want to generate that code block.  Also uncomment line 8 and define whether you want that snippet to be workable only in a specific scope of scripting.

Finally save the file in /Users/USERNAME/Library/Application\ Support/Sublime\ Text\ 2/Packages/User  (Mac OSX) folder with a name along with .sublime-snippet extension.

Screen Shot 2013-08-29 at 4.26.04 PM

Here I have made a simple snippet which contains a template of a basic JQuery plugin. You can Download this snippet file and paste it inside the folder /Users/USERNAME/Library/Application\ Support/Sublime\ Text\ 2/Packages/User (Mac OSX)

Screen Shot 2013-08-29 at 4.12.36 PMThen you can start writing jquery on any type of file (As I did not define any scope) and the snippet keyword should appear.

Screen Shot 2013-08-29 at 4.14.14 PM

Press tab key by typing jqueryplugin OR enter/return key by selecting that suggestion and it will generate a basic template of a jquery plugin there for you.

Screen Shot 2013-08-29 at 4.14.22 PM

Deploy Application in Amazon Beanstalk inside free EC2 Instance with RDS

Amazon has virtual cloud server (instance) and many other web services. They offers a 1 year free micro tier to be used by anyone who own an international currency Debit/Credit card like Payoneer debit master card. There are several services included with the free tier that can be used along with the EC2 instance without any extra charge. Beanstalk deployment framework is one of the free services you are eligible for.

For no additional charge, AWS Elastic Beanstalk allows you quickly and easily deploy your Java, PHP, Python, Ruby, and .NET applications using many of the services offered in the free usage tier.” -Amazon. Beanstalk is similar to other deployment frameworks like appfog, pagodabox etc. Moreover if you use Beanstalk then you will still have access to your virtual cloud server in which the deployment will be running. “Behind the scenes, Elastic Beanstalk handles the provisioning of a load balancer and Amazon EC2 resources.” -Amazon. Thats why I prefere Beanstalk than others who are in my knowledge.

In this post we will cover the steps of creating an account for Amazon EC2 free tier, configuring local machine for Amazon CLI tools, creating a sample app locally, creating an elastic beanstalk php environment, deploying a sample php app, creating an Amazon RDS and connecting to it via PHP and mySQL workbench, git version controlling of the deployed app, setting up a custom classified domain to our newly deployed app environment. Tired to read these ? I am sure you will feel best after having this journey 🙂

1. Create an account for Amazon web service from here . You can see the service list that will be included with your free tier for your further using. Note that, the sign up process is simple and you will be asked to provide your card detail on the second step and finally you will have to verify your phone number. You will have to put your phone number then to click “call now” button then a 4 digit pin number will be appeared on your browser. After that an automated call will reach your phone. You should either speak the pin number slowly or input the pin number in your mobile keypad if it supports touchtone functionality. I always spoke the pin after listening the bot girl’s voice 🙂 Continue reading Deploy Application in Amazon Beanstalk inside free EC2 Instance with RDS

How to show/hide hidden files-folders in Mac (Lion)

Yes, its those who are facing problems while trying to finding out a hidden files or folders in your Mac filesystem using Mac finder 🙂

Execute these two commands in your Mac Terminal and again open the Finder. You should see them 🙂

How to install Citycell Zoom ZTE AC2726 modem on Mac OSX Lion 10.7.x

1. Download the application from here: Dropbox Link
2. Install it on your Mac
3. Plugin your Zoom Modem.
4. Ignore any auto installation if occurred. Just launch the installed app.
5. Configure phone, user, pass to #777 , waps , waps  respectively under [settings] then press the [netconnect] button