Home > Software design >  Method Illuminate\Database\Schema\Blueprint::comment does not exist
Method Illuminate\Database\Schema\Blueprint::comment does not exist

Time:12-21

I need a help about a easy question, when I use the following code

DB::statement("ALTER TABLE user comment 'User comment'");

this code work in my laravel migration.

But when I use same code laravel documentantion

Schema::create('user', function (Blueprint $table) { $table->comment('User comment'); });

My output in the terminal is as follows

BadMethodCallException

Method Illuminate\Database\Schema\Blueprint::comment does not exist.

I tried

Schema::create('user', function (Blueprint $table) { $table->comment('User comment'); });

I expected results is succesfull

CodePudding user response:

You should define the column first before you use the comment(). Since the comment is a method from the Illuminate\Database\Schema\ColumnDefinition::class you cannot access it using the $table which is an instance of Illuminate\Database\Schema\Blueprint::class :

$table->string('name'); // Return type is ColumnDefinition class it means the you can access the comment() after the string(),

$table->string('name')->comment('Name of the user');

Laravel - Column Modifiers

CodePudding user response:

Migration table comments for MySQL and Postgres are released with laravel version 9.14: https://laravel-news.com/laravel-9-14-0

So, if you want to use this feature, you have to update your laravel version.

  • Related