Created
April 18, 2017 18:36
-
-
Save theMadness/906389a4c41ab114fa9a90776be3e553 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Database\Migrations\Migration; | |
use Illuminate\Database\Schema\Blueprint; | |
use Illuminate\Support\Facades\Schema; | |
class MediaModuleUpdate extends Migration | |
{ | |
/** | |
* Run the migrations. | |
* | |
* @return void | |
*/ | |
public function up() | |
{ | |
Schema::table('profiles', function (Blueprint $table) { | |
$this->upMedia($table, 'media'); | |
}); | |
} | |
/** | |
* Reverse the migrations. | |
* | |
* @return void | |
*/ | |
public function down() | |
{ | |
Schema::table('profiles', function (Blueprint $table) { | |
$this->downMedia($table, 'media'); | |
}); | |
} | |
private function upMedia(Blueprint $table, $columnName) | |
{ | |
$table->unsignedInteger($columnName.'_res')->nullable(); | |
$table->foreign($columnName.'_res') | |
->references('resourcesid') | |
->on('resources') | |
->onDelete('set null'); | |
$table->unsignedInteger($columnName.'_thumb_res')->nullable(); | |
$table->foreign($columnName.'_thumb_res') | |
->references('resourcesid') | |
->on('resources') | |
->onDelete('set null'); | |
} | |
private function downMedia(Blueprint $table, $columnName) | |
{ | |
$table->dropForeign([$columnName.'_res']); | |
$table->dropForeign([$columnName.'_thumb_res']); | |
$table->dropColumn($columnName.'_res'); | |
$table->dropColumn($columnName.'_thumb_res'); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment