Skip to content

Instantly share code, notes, and snippets.

@xeoncross
Created February 15, 2013 21:16
Show Gist options
  • Save xeoncross/4963609 to your computer and use it in GitHub Desktop.
Save xeoncross/4963609 to your computer and use it in GitHub Desktop.
Create and Edit Database Schema's with Laravel's new Illuminate libraries.
<?php
require 'vendor/autoload.php';
//require 'SplClassLoader.php';
//$classLoader = new SplClassLoader();
//$classLoader->register();
// Must manually include these :(
require 'Illuminate/Support/helpers.php';
/*
* Uses laravel schema builder to produce schema's for us!
*/
$grammar = new Illuminate\Database\Schema\Grammars\SQLiteGrammar;
//$grammar = new Illuminate\Database\Schema\Grammars\MySqlGrammar;
$grammar->setTablePrefix('prefix_');
$table = new \Illuminate\Database\Schema\Blueprint('users');
$table->create();
$table->increments('id');
$table->string('email', 100)->nullable()->default('bar');
$table->string('username')->unique();
$table->string('phone')->nullable();
$table->text('about');
// created_at, updated_at
$table->timestamps();
$table->dropColumn('phone');
$table->foreign('order_id')
->references('id')->on('orders')
->onDelete('restrict')->onUpdate('cascade');
$table->index(array('foo', 'bar'), 'baz');
$statements = $table->toSql($grammar);
print_r($statements);
/*
http://laravel.com/docs/database/schema
https://github.com/laravel/framework/blob/master/tests/Database/DatabaseMySqlSchemaGrammarTest.php
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment