Laravel DB: Set Default Values in Eloquent Model #laravel

preview_player
Показать описание
Support the channel by checking out my products:

Other places to follow:
Рекомендации по теме
Комментарии
Автор

Good one, thnx.
Especially now that sqlite is the default. Sqlite doesnt allow for alter column. So changing default value of a column is a hassle if you put that in the migration. This is the way to go.

akyaren
Автор

Is it safe to say that we can then remove the ->default() when creating the table migrations, and simply rely on the models default $attributes?

Dayne
Автор

can we pass the auth()->user()->id in it? in some case i want to use current user id as a default value. is it possible to use this default value method instead of Observer?

StayFahmousss
Автор

Nah i prefer using migrations. It's much easier to export and just rerun that way. Also migrations are stored in the database so you don't have to worry anything even if you ruin the model

tyrellwreleck
visit shbcf.ru