Create a PostgreSQL table with a JSON column to store your timestamps (call it metadata, for instance)
Create a model using that metadata column for your timestamps and enable soft delete
class MyClass extends Model
{
use SoftDeletes;
public const CREATED_AT = 'metadata->created_at';
public const UPDATED_AT = 'metadata->updated_at';
public const DELETED_AT = 'metadata->deleted_at';
...
}
Create a new record and save it in the database ; the metadata column will be correctly filled with {"created_at": ...}
Description:
When using a
JSON
column in PostgreSQL for timestampscreated_at
,updated_at
, anddeleted_at
, there is an issue with update and (soft) delete.Error on update
Query:
Error on delete
Error is triggered by
syncOriginalAttributes()
function. https://github.com/laravel/framework/blob/ae6098381ad5cd4eb44394f0b2395c855c086684/src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php#L1809-L1820Steps To Reproduce:
Create a PostgreSQL table with a
JSON
column to store your timestamps (call itmetadata
, for instance)Create a model using that
metadata
column for your timestamps and enable soft deleteCreate a new record and save it in the database ; the
metadata
column will be correctly filled with{"created_at": ...}
Try to update it (first error)
Try to (soft) delete it (second error)