Image Image Image Image Image
Scroll to Top

To Top

THEMWEBS - Portfolio & blog of Mannuel Ferreira

Database migrations, PHP with Laravel

On 16, Jun 2018 | No Comments | In Database, Laravel, PHP | By Manny

Database migrations are an awesome concept in software engineering that allow you to keep track of the state of your database. When I say state I mean history, you can go back in time and update and delete fields. It is also known as a schema migration.

I work with PHP using the Laravel framework. Laravel have an awesome command line tool called artisan, which you can use you create new databases, update existing fields, rename existing columns, new columns and delete fields.

Migrations allow you to make incremental changes to you database, you can go back in history and create the future by adding new fields to your database, it really is quite amazing.

Lets build a music app together. What do all music apps need? songs, great, so we need a table to store all of our songs, great.

What will our table look like? what fields do we need? Lets think about the data that we want to store for a minute. All songs have a title, an artist(s), the date it was made and maybe a remix artist.

There we have it we have just planned out out schema for our table.

  • id
  • title
  • artist
  • remixed_by
  • released

First create Laravel project

// create project 
laravel new muziks

// rename evn file
mv .env.example .env

// generat key
php artisan key:generate

// ok lets go...

// login to mysql (local but sure use docker if you like)
mysql -uroot -proot

// create database
| Database                            |
| muziks                              |

// run create
php artisan make:migration create_songs_table

You should have a time stamped file with the name of the migration


Next open the migration file and lets fill in our schema, the fields of the table.

In out migration file we have up() and down() method. The up method will flesh out our planned schema. So when you do a php artisan migrate Laravel will go ahead and create the given table with the given fields. The down method will delete the table.


use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateSongsTable extends Migration
     * Run the migrations.
     * @return void
    public function up()
        Schema::create('songs', function (Blueprint $table) {
            // Here we adding our tables' fields 

     * Reverse the migrations.
     * @return void
    public function down()
        // this will delete the table when

Next create the migrations.

// run migrations
php artisan migrate

You should have a table like this:

If you want to rollback the migration, you can do this:

// rollback migration
php artisan migrate:rollback



No Comments

In JavaScript

By Manny

Async HTTP Requests

On 15, Jun 2018 | No Comments | In JavaScript | By Manny

Working with the web you will have to at some point get some data from some where. You might like to call an API. Here is an example of a classic XML HTTP request. There are more modern ways of retrieving data, like using fetch() api, thats cool… I will make another post about this.

Async is short for Asynchronous. This means an operation that happens one at a time after the previous operation has completed.

XML HTTP Request


fizzbuzz – JavaScript

On 13, Jun 2018 | No Comments | In Computer Science, JavaScript | By Manny

Fizzbuzz Programme, is a program that prints the numbers from 1 to 100.

For the multiples of three print “Fizz” instead of the number and for the multiples of five print “Buzz”.

For numbers which are multiples of both three and five print “FizzBuzz”