Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.