D
D
Dimon3x2019-02-28 14:43:17
Laravel
Dimon3x, 2019-02-28 14:43:17

How to populate the default table when creating migrations?

I'm creating a migration of categories and subcategories.

public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->increments('id');
             $table->char('category_name', 100);
             $table->char('title_in_english', 100); //для того, что бы вывести все посты главной категории
        });
    }

public function up()
    {
        Schema::create('sub_categories', function (Blueprint $table) {
            $table->increments('id');
            $table->char('sub_category_name', 100);
            $table->integer('id_category');
        });
    }

How to make it so that after performing the migrations, there are already some data in the database?
For example, for categories
category_name = Изображения
title_in_english = images

category_name = Видео
title_in_english = videos

For sub_categories
sub_category_name = Автомобили
id_category = 1

sub_category_name = Дом
id_category = 2

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alexander, 2019-02-28
@Dimon3x

For this there is Database: Seeding

A
Alexey Ukolov, 2019-02-28
@alexey-m-ukolov

Directly in the migration and add them. Through the model , through the factory or through direct requests - whatever.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question