FEATURE: change directory structure
This commit is contained in:
@@ -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');
|
||||
// });
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user