Tryin’ to find a way to set default model values in Eloquent model (speaking about Laravel ORM) I was surprised that there’s no any mention about it in official docs. So thanks to fellas from StackOverflow such a workaround was found:
1 2 3 4 5 6 7 |
class FooModel extends Model { protected $attributes = array( 'foo' => 'bar' ); } |
This example shows you how to set default value to ‘foo’ model property (model field, attribute, etc) if you’re creating a new FooModel record. Читать далее