Skip to content

Instantly share code, notes, and snippets.

@thunderrabbit
Created August 14, 2014 15:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thunderrabbit/6130543037c7538075bc to your computer and use it in GitHub Desktop.
Save thunderrabbit/6130543037c7538075bc to your computer and use it in GitHub Desktop.

AddForeignkeysToUsersTable

	public function up()
	{
		Schema::table('users', function($table) {
			$table->foreign('department_id')->references('id')->on('departments');
			$table->foreign('role_id')->references('id')->on('roles');
		});
	}

	public function down()
	{
		Schema::table('users', function($table){
			$table->dropForeign('users_department_id_foreign');
			$table->dropForeign('users_role_id_foreign');
			$table->dropIndex('users_department_id_foreign');
			$table->dropIndex('users_role_id_foreign');
		});
	}

AddForeignkeysToRolesTable

	public function up()
	{
		Schema::table('roles', function($table) {
			$table->foreign('department_id')->references('id')->on('departments');
		});
	}

	public function down()
	{
		Schema::table('roles', function($table){
			$table->dropForeign('roles_department_id_foreign');
			$table->dropIndex('roles_department_id_foreign');
		});
	}

AddForeignkeysToTransactionsTable

	public function up()
	{
		Schema::table('transactions', function($table) {
			$table->foreign('department_id')->references('id')->on('departments');
		});
	}

	public function down()
	{
		Schema::table('transactions', function($table){
			$table->dropForeign('transactions_department_id_foreign');
			$table->dropIndex('transactions_department_id_foreign');
		});
	}

AddForeignkeysToRolestransactionsTable

	public function up()
	{
		Schema::table('rolestransactions', function($table) {
			$table->foreign('transaction_id')->references('id')->on('transactions');
			$table->foreign('role_id')->references('id')->on('roles');
		});
	}

	public function down()
	{
		Schema::table('rolestransactions', function($table){
			$table->dropForeign('rolestransactions_transaction_id_foreign');
			$table->dropForeign('rolestransactions_role_id_foreign');
			$table->dropIndex('rolestransactions_transaction_id_foreign');
			$table->dropIndex('rolestransactions_role_id_foreign');
		});
	}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment