S
S
SrnkWeb2021-05-28 13:06:54
Laravel
SrnkWeb, 2021-05-28 13:06:54

After creating the migration, do you need to manually correct the table name in the method schema, or is there another way?

Good day, I write the command php artisan make:model Article -m in the console, a model is created and a migration with the names (Model - Article.php), (migration - 2021_05_28_092527_create_article_table.php. There are two defined methods up() and down( ) in which Schema:: XXXXXX('article') is specified with the table name for working with DB, by agreement in Laravel 8, the table must be in the plural, i.e. articles After creating the migration, you need to manually correct the table name in the method schema or is there another way?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey delphinpro, 2021-05-28
@delphinpro

You can fix it manually too.
But in general, everything should be created right away.
Here's what I just checked:

artisan make:model Article -m
Model created successfully.
Created Migration: 2021_05_28_111836_create_articles_table

class CreateArticlesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('articles', function (Blueprint $table) {
            $table->id();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('articles');
    }
}

S
SrnkWeb, 2021-05-28
@SrnkWeb

I found the answer to my own question. When I created the model and migration using artisan with
php artisan make:model -m TransactionManagement.
Got this result in migration 2021_05_28_111309_create_transaction_management_table.php , expected result should look like this the result is 2021_05_28_112833_create_transaction_managemens_table.php, respectively in the schema
Schema:: XXXXXX('transaction_managemens') the required table is specified, it seems that the problem was in the reserved name (but this is not accurate :)). Above the post, I was too lazy to write long names, so I used the short name Article in the question being asked, as it turned out, I had to write it as it is. Thank you for your attention )))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question