Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function up()
- {
- DB::transaction(function () {
- if (!Schema::hasTable('news_translations')) {
- Schema::create('news_translations', function (Blueprint $table) {
- $table->increments('id');
- $table->integer('news_id')->unsigned();
- $table->foreign('news_id')->references('id')->on('news');
- $table->string('name', 500);
- $table->text('content');
- $table->text('description');
- $table->string('locale', 50);
- });
- }
- $old_news = News::all()->toArray();
- foreach ($old_news as $news_item) {
- foreach (LocaleService::AVAILABLE_LOCALES as $prefix) {
- NewsTranslations::create([
- 'news_id' => $news_item['id'],
- 'name' => $news_item['name'],
- 'description' => $news_item['description'],
- 'content' => $news_item['content'],
- 'locale' => $prefix
- ]);
- }
- }
- if (Schema::hasTable('news')) {
- Schema::table('news', function (Blueprint $table) {
- $table->dropColumn('name');
- $table->dropColumn('description');
- $table->dropColumn('content');
- });
- }
- });
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement