Moreover, they ended up making application’s code appear messy, where SQL statements seemed entwined with PHP code. With version 5.0, PHP language generated an integrated interface to fetch the results and query databases while the other new features that added with proved useful to handful of basic applications. Taking in traditional terms, data of PHP web applications is stored in database table rows. Working over data acts as a crucial part of every web application. This is by far the simplest way to create many-to- many relationships. $table->integer(‘zoo_id’) // the id of the zoo in which the bear is at $table->integer(‘lions_id’) // id of the lion Schema::create(‘lions_zoo’, function(Blueprint $table) app/database/migrations/#_#_#_#_create_bears_picnics_table.php Php artisan migrate:make create_lions_zoo_table –create=lions_zoo To define many-to-many relationship we need to write the following code Similarly, we can create a migration named as Zoo and we can relate them using a pivot table. It automatically updates the record when it is updated. Furthermore, timestamps for the field updated_at and created_at. $table->integer(‘danger_level’) // specifying ageĪuto-increment id is included in these migrations. Schema::create(‘lion’, function(Blueprint $table) app/database/migrations/create_lion_table.php We can use this field to specify the fields as mentioned below. Php artisan migrate:make create_fish_table –create=fish
We can easily create a migration by a command line type. However, I am trying here to create a simple table named as lion. To get detailed information about it you can refer Laravel docs. We know that we Migrations are the easiest way to add tables in the database. Modify your database settings in app/config/database.php.
Read More:- PHP framework developer Eloquent ORM in Laravel: How Does It Work?Įloquent ORM in Laravel offers an ActiveRecord implementation for database to work with, which means that every model created in MVC structure resembles to a table of the database. Eloquent ORM in Laravel has made it extremely effortless for programmers to interact with database. Starting with the building blocks of this massive topic, programmers can learn to roll in. If you are PHP programmer and have strong grip in working with “Objects” in PHP, you might be well aware of the utility of Eloquent! It is not easy, but undoubtedly, the most expressive syntax in PHP especially when it comes to working with Models. Laravel Eloquent ORM or Object Relational Mapper is not just impressive, but expressive as well.