Skip to content

Instantly share code, notes, and snippets.

@thunderrabbit
Created August 14, 2014 15:39
Show Gist options
  • Select an option

  • Save thunderrabbit/6130543037c7538075bc to your computer and use it in GitHub Desktop.

Select an option

Save thunderrabbit/6130543037c7538075bc to your computer and use it in GitHub Desktop.

Revisions

  1. thunderrabbit renamed this gist Aug 14, 2014. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. thunderrabbit created this gist Aug 14, 2014.
    82 changes: 82 additions & 0 deletions 8b1230de6c789d683721
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,82 @@
    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');
    });
    }
    ```