FEATURE: change directory structure

This commit is contained in:
Michal Kváček
2016-10-17 00:07:21 +02:00
parent 87f1920373
commit 2ded2924a1
242 changed files with 742 additions and 1171 deletions
@@ -0,0 +1,68 @@
<?php
use App\Models\Widgets\WidgetType;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class MigrateWidgetHandlersToNewStructure extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('widgets', function (Blueprint $table) {
$table->dropForeign('widgets_widget_type_handler_foreign');
});
Schema::table('widgets', function (Blueprint $table) {
$table->foreign('widget_type_handler')
->references('handler')
->on('widget_types')
->onDelete('cascade')
->onUpdate('cascade');
});
$widgets = WidgetType::where('handler', 'LIKE', '%App%')
->get();
foreach ($widgets as $widget) {
$widget->handler = str_replace('App\Widgets', 'App\CMS\Widgets', $widget->handler);
$widget->save();
}
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
// Schema::table('widgets', function (Blueprint $table) {
// $table->dropForeign('widgets_widget_type_handler_foreign');
// });
$widgets = WidgetType::where('handler', 'LIKE', '%App%')
->get();
foreach ($widgets as $widget) {
$widget->handler = str_replace('App\CMS\Widgets', 'App\Widgets', $widget->handler);
$widget->save();
}
// Schema::table('widgets', function (Blueprint $table) {
// $table->foreign('widget_type_handler')
// ->references('handler')
// ->on('widget_types')
// ->onDelete('cascade')
// ->onUpdate('cascade');
// });
}
}