Exemplo n.º 1
0
 /**
  * Install the database tables used by the migration system.
  *
  * @return void
  */
 public function install()
 {
     Schema::table('laravel_migrations', function ($table) {
         $table->create();
         // Migrations can be run for a specific bundle, so we'll use
         // the bundle name and string migration name as an unique ID
         // for the migrations, allowing us to easily identify which
         // migrations have been run for each bundle.
         $table->string('bundle', 50);
         $table->string('name', 200);
         // When running a migration command, we will store a batch
         // ID with each of the rows on the table. This will allow
         // us to grab all of the migrations that were run for the
         // last command when performing rollbacks.
         $table->integer('batch');
         $table->primary(array('bundle', 'name'));
     });
     echo "Migration table created successfully.";
 }
 /**
  * Revert the changes to the database.
  *
  * @return void
  */
 public function down()
 {
     Schema::drop('laravel_schema');
 }
Exemplo n.º 3
0
 /**
  * Create a new table
  * 
  * <code>
  * // input example
  * $input = array(
  *   'posts' => array(
  *     'title' => array(
  *       'type' => 'string',
  *       'length' => 100,
  *     ),
  *   ),
  *   // Can add multiple tables at once
  *   'post_lang' => array(
  *     'name' => array(
  *       'type' => 'string',
  *     ),
  *     'locale' => array(
  *       'type' => 'string',
  *       'length' => 5,
  *     ),
  *   ),
  * );
  * 
  * DBManager::new_table($input);
  * 
  * </code>
  *
  * @param array $input
  * @return array
  */
 public static function new_table($input)
 {
     foreach ($input as $table => $columns) {
         Schema::create($table, function ($table) use($columns) {
             if (!isset($columns['id'])) {
                 $table->increments('id');
             }
             foreach ($columns as $name => $data) {
                 if (isset($data['length']) and !is_null($data['length'])) {
                     ${$name} = $table->{$data['type']}($name, $data['length']);
                 } else {
                     ${$name} = $table->{$data['type']}($name);
                 }
                 if (isset($data['nullable']) and $data['nullable'] == true) {
                     ${$name}->nullable();
                 }
             }
             $table->timestamps();
         });
     }
     return DBManager::tables();
 }