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 IlluminateDatabaseSchemaBlueprint::comment does not exist.
I tried
Schema::create('user', function (Blueprint $table) { $table->comment('User comment'); });
I expected results is succesfull
3
Answers
I was using PHP 7 and the installation of Laravel contemplated version 8, after migrating to PHP 8 it was possible to install Laravel 9 in which the syntax worked
You should define the column first before you use the
comment()
. Since thecomment
is a method from theIlluminateDatabaseSchemaColumnDefinition::class
you cannot access it using the$table
which is an instance ofIlluminateDatabaseSchemaBlueprint::class
:Laravel – Column Modifiers
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.