Build Database with the Schema Builder Class In Laravel 5.1

Learn how to setup your first project in laravel

Our development environment is now ready. No more worries, and a whole new world awaits: the hero left his home. Little by little, step by step, he is going forward toward the goal. The hero knows what is really important: to stay grounded. Having a good foundation helps. No big differences for an application: a well-designed database for your project is always the best start.

Starting from this important assumption, the question naturally arises: is there a way, with Laravel, to deal with the design of a database before using it, maybe in a smart way that you can easily manage? The answer is, as you can imagine, yes.

In this tutorial, we will look at the Schema Builder class. A very important class that lets you design your entire database without writing a single SQL line! Quite impressive if you think about it, considering that it is quite possible that you will build your entire application on a SQL database without using SQL! We will analyze everything you can do with the class: creating, dropping, and updating a table; adding, removing, and renaming columns. Also, we will look at indexing in many ways: not only simple indexes but also unique indexes and foreign keys. Also, we are going to look at some methods that the Schema class provides in order to have a real and total control over everything. Sometimes, you will need to be sure about what exists in your database!

After all this stuff, it is not be over yet. In fact, we will explore the world of migrations, which is something Laravel uses to do versioning of your database. Combining the power of the Schema class with the migrations system will give you great power over your data design. Also, it will be very easy to share your application with another new member of your team! You know that versioning is always the best choice.

An important note before going forward: even if the Schema Builder class and migrations system are not tightly related to Eloquent, they easily create a database with a structure that fits perfectly for the Eloquent standards and conventions. Also, the Schema Builder and migrations system are a part of the illuminate/database (https://github.com/illuminate/database) package; yes, the same package from Eloquent! Let’s go.

About the author

Deven Rathore

I'm Deven Rathore, a multidisciplinary & self-taught designer with 3 years of experience. I'm passionate about technology, music, coffee, traveling and everything visually stimulating. Constantly learning and experiencing new things.

Pin It on Pinterest

Shares