There is no license information available for the latest version (dev-master) of this package.

dev-master 2014-03-31 12:52 UTC

This package is not auto-updated.

Last update: 2024-12-16 15:49:27 UTC


README

With this package you can:

  • Generate an Eloquent model as a file and export it to the database.
  • Use a fluent interface to write the model specs
  • Define cross relationships between models

Install

Use [Composer] (http://getcomposer.org) to install the package into your application

require {
    "boyhagemann/model": "dev-master"
}

Then add the following line in app/config/app.php:

...
"Boyhagemann\Model\ModelServiceProvider"
...

Example usage

// Get a fresh ModelBuilder instance
$mb = App::make('ModelBuilder');

// Set the name of the model class
$mb->name('Article');

// Set the database table
$mb->table('news');

// Change the folder where to store this model
$mb->folder('/app/models');
   
// Add columns to the table, each with their own fluent interface
// depending on their type of column.
$mb->string('title')->required();
$mb->text('description')->length(50);
$mb->integer('number_of_views');

// Add relationships, each with their own fluent interface
// depending on their type of relationship.
$mb->hasOne('Category');

Auto-generating and updating models

This package checks if the model exists yet in the IoC container. If it doesn't, then the Eloquent model file is written to disk and the database table is created. During development it may be handy to keep updating your database the moment you changed your configuration.

$mb->autoGenerate();