A Laravel migration is stored in your application’s app/database/migrations folder. Each file deal with some set of chnages for the corresponding databases. Changes to the database are made in PHP rather than a database-specific flavour of SQL. Your PHP migration code ends up being converted into the DDL specific to your current database; this makes switching database platforms very easy. Since migrations are kept in their own directory, it’s pragmatic to include them into version control just like any other project code. Laravel migrations are run explicitly from command-line using the artisan tool.

Now we have to deal with migration:
We are going to use Laravel’s command line tool artisan to create our new migration. To run artisan you will need to open a terminal to the root of your Laravel application folder where the artisan script exists. The first thing we need to install the migration table, so that Laravel can keep track of which migrations have been run. Run below command to create the special table in database.

If success, artisan will respond with a message “Now we’re ready to do some migrating!” and you can see database table “migrations”. You don’t need to be overly concerned about the table. This is simply a table that helps Laravel to keep tabs on the migrations that you have and have not run. When you add new migrations, artisan migrate will check the migrationstable and execute all migrations that have not yet run.

Read More

Model (Eloquent ORM)
The Eloquent ORM is responsible for the database operations(Model). By using this we can avoid the sql quering. The eloquent model files are placed in app/model directory. Every databse table have a eloquent file.

Here this eloquent will deal with the ‘my_users’ table in database. If we do not specify the table here then laravel will take the plural form of the class name as the table name ie, here it is ‘users’.

We can access a model function by calling in the following manner:
Display corresponding model values: $model = User::display()
Insert value to database:
$user = new User;
$user->name = ‘Test Name’;

Insert value in database using ‘create’ method:
$user = User::create(array(‘name’ => ‘Test Name’)); // Create a new user in the database.
$user = User::firstOrCreate(array(‘name’ => ‘Test Name’)); // Retrieve the user by the attributes, or create it if it doesn’t exist.
$user = User::firstOrNew(array(‘name’ => ‘Test Name’)); // Retrieve the user by the attributes, or instantiate a new instance…

Updating a database values:
$user = User::find(1); //load record by id
$user->email = ‘[email protected]’; //load new value
$user->save(); //update new value

Delete record:
$user = User::find(1); //load record by id
$user->delete(); //delete record

Read More

Laravel is a free,open source PHP web application framework, designed for the development of MVC web applications. Laravel, being a web application framework with expressive, elegant syntax. Laravel is accessible, yet powerful, providing powerful tools needed for large, robust applications.
Some features of laravel:

  • Easy and convenient templating using Blade, a great templating engine built for Laravel.
  • Awesome routing facilities.
  • Eloquent, an elegant and one-of-a-kind object-relational mapper.
  • Artisan, Laravel’s amazing CLI, which helps with database migrations, project management, and so on … you can even create your own commands.
  • A modular architecture powered by Composer, which makes it easier to build scalable and less coupled apps.
  • Amazing documentation.
  • An active and supportive community.
  • Marvelous testing facilities to make sure your apps are doing what you think they are etc.

Eloquent Driver: It is driver provided by laravel. Eloquent is also the name of the ORM which Laravel provides, for abstracting model data. It is similar in that it will ultimately query a database to determine whether a user is authentic, but the interface which it uses to make that determination is quite different from direct database queries. If you’re using Laravel to build medium-to-large applications, then you stand a good chance of using Eloquent models to represent database objects.

Read More