hi @d_martiuk could u show how u create the record?
Can't get model attributes which was created by default in DB
I have migration with setting default values
Schema::create('payments', function (Blueprint $table) {
$table->uuid('id')->primary();
$table->string('type')->default(PaymentType::Base->value);
$table->string('provider', 5)->default('w4p');
$table->string('status')->default(PaymentStatus::NotPaid->value);
$table->string('regularMode');
$table->string('membership', 10)->default(PaymentMembership::Single->value);
$table->string('clientFirstName')->nullable();
$table->string('clientLastName')->nullable();
$table->string('clientEmail')->nullable();
$table->timestamp('orderDate')->useCurrent();
..........
});
}
And after the entity is created, attributes that were created by default or cast return NULL. If you set dd after creation and set this created object, the attributes will not have the values that were created by default or were casted inside model
But If i get from created payment id and call Payment::find($payment->id), all the attributes are in place
@d_martiuk Ok i see try doing this instead
$payment->refresh();
here the link to the docs if u want to take a look https://laravel.com/docs/10.x/eloquent#refreshing-models
" The refresh method will re-hydrate the existing model using fresh data from the database. In addition, all of its loaded relationships will be refreshed as well "
Please or to participate in this conversation.