Advertisement
Guest User

Untitled

a guest
Jan 17th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.49 KB | None | 0 0
  1. public function up()
  2. {
  3. DB::transaction(function () {
  4. if (!Schema::hasTable('news_translations')) {
  5. Schema::create('news_translations', function (Blueprint $table) {
  6. $table->increments('id');
  7. $table->integer('news_id')->unsigned();
  8. $table->foreign('news_id')->references('id')->on('news');
  9. $table->string('name', 500);
  10. $table->text('content');
  11. $table->text('description');
  12. $table->string('locale', 50);
  13. });
  14. }
  15. $old_news = News::all()->toArray();
  16. foreach ($old_news as $news_item) {
  17. foreach (LocaleService::AVAILABLE_LOCALES as $prefix) {
  18. NewsTranslations::create([
  19. 'news_id' => $news_item['id'],
  20. 'name' => $news_item['name'],
  21. 'description' => $news_item['description'],
  22. 'content' => $news_item['content'],
  23. 'locale' => $prefix
  24. ]);
  25. }
  26. }
  27. if (Schema::hasTable('news')) {
  28. Schema::table('news', function (Blueprint $table) {
  29. $table->dropColumn('name');
  30. $table->dropColumn('description');
  31. $table->dropColumn('content');
  32. });
  33. }
  34. });
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement