Ad

Why Does Php Artisan Create Migration Class With Empty Up Method?

I am currently learning from this video

https://laracasts.com/series/laravel-from-scratch-2018/episodes/7

about database migrations in laravel. I typed in console :

php artisan make:migration create_projects_table

just like the teacher in the video and somehow I get an empty method definition in the migrations folder.

use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateProjectsTable extends Migration
{

    public function up()
    {
        //should contain Schema::create but it is empty
    }


    public function down()
    {

    }
}

What did I do wrong? I followed all those instructions in the video.

Ad

Answer

You can specify the table:

php artisan make:migration create_projects_table --create=projects

edit: It should indeed work without adding the argument: https://github.com/laravel/framework/blob/854e6d1d001f5e9a6d1376d2284eaa99b0c1e443/src/Illuminate/Database/Console/Migrations/MigrateMakeCommand.php#L88

        // Next, we will attempt to guess the table name if this the migration has
        // "create" in the name. This will allow us to provide a convenient way
        // of creating migrations that create new tables for the application.
        if (! $table) {
            [$table, $create] = TableGuesser::guess($name);
        }

The tableGuesser class

Here you can see that your tables name should match (\w+) pattern

Ad
source: stackoverflow.com
Ad