Default values are defined in /vendor/laravel/framework/src/Illuminate/Database/Schema/Blueprint.php as defaults to method params. So the only way you could change that would probably be to make your own implementation of that class, and force eloquent to use it instead. Seems like a lot of work for no real gain. Are you really that concerned about the extra 64 characters? Why not, instead, just either define it in the migration, as it's designed, or implement validation rules to prevent longer values being stored?
Migrations: Configure a default string length? (utf8mb4)
For forward-compatibilty with emoji and such, I'm configuring my database to use utf8mb4 throughout. I have updated my config/database.php to use utf8mb4:
'mysql' => [
...
'charset' => 'utf8mb4',
'collation' => 'utf8mb4_unicode_ci',
...
]
And now my migrations now create tables with utf8mb4 encoding. Awesome! The only problem is that string columns are still set to a length of 255 when they should be only 191.
I know that I can specify a max VARCHAR length in the migration itself:
$table->string('name', 191);
...but I dislike the idea hard-coding fixed numbers for every string colum in the database. I feel like the size argument should only be used for ad hoc overrides, but maybe that's just me.
I'd like to set a default VARCHAR size somewhere and have the migrations use that instead, but I'm not sure where to look. Is there a preferred place for such a configuration to go? Should I just shim it in somehow?
Please or to participate in this conversation.