Skip to content

Instantly share code, notes, and snippets.

@theMadness
Created April 18, 2017 18:36
Show Gist options
  • Save theMadness/906389a4c41ab114fa9a90776be3e553 to your computer and use it in GitHub Desktop.
Save theMadness/906389a4c41ab114fa9a90776be3e553 to your computer and use it in GitHub Desktop.
<?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