| Total Complexity | 7 |
| Total Lines | 24 |
| Duplicated Lines | 0 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 6 | class AddLocaleColumnToTwillMediables extends Migration |
||
| 7 | { |
||
| 8 | public function up() |
||
| 9 | { |
||
| 10 | if (Schema::hasTable('mediables') && !Schema::hasColumn('mediables', 'locale')) { |
||
| 11 | Schema::table('mediables', function (Blueprint $table) { |
||
| 12 | $table->string('locale', 7)->default($this->getCurrentLocale())->index(); |
||
| 13 | }); |
||
| 14 | } |
||
| 15 | } |
||
| 16 | |||
| 17 | public function down() |
||
| 18 | { |
||
| 19 | if (Schema::hasTable('mediables') && Schema::hasColumn('mediables', 'locale')) { |
||
| 20 | Schema::table('mediables', function (Blueprint $table) { |
||
| 21 | $table->dropIndex('mediables_locale_index'); |
||
| 22 | $table->dropColumn('locale'); |
||
| 23 | }); |
||
| 24 | } |
||
| 25 | } |
||
| 26 | |||
| 27 | function getCurrentLocale() |
||
| 28 | { |
||
| 29 | return getLocales()[0] ?? config('app.locale'); |
||
| 30 | } |
||
| 32 |