Support the ongoing development of Laravel.io →
Requests Database Architecture

I'm using DB::transaction and SoftDeletes.

For those unfamiliar with Laravel the SoftDelete functionality of Laravel abstracts away the setting / querying of rows in the database. When a record is deleted the field deleted_at is given a timestamp otherwise this field is null. This field is then used on querying to only get non deleted rows.

Currently I have a script that runs every day that deletes all the soft deleted entries that are older than 7 days.

enter image description here This is where my question/problem is. What if my DB::transaction spanned for let's say 2 minutes and add the end writes to Table A and Table B so that the entries in both tables have a different timestamp.

I can picture a scenario where when the cleanup script executes it could delete HALF of the entry records.

My question then is

  1. would a DB::transaction give the same timestamp to all the records?
  2. if not how can I remedy this problem?
Last updated 3 years ago.
0
  1. Pass
  2. Set a variable to the current date/time and use this in all db statements - if you need it when the transaction completes I guess you could update each table with a date/time var after the transaction completes
0

Thanks elite123, well the biggest problem is the deleted_at field by the soft delete is set for me automatically so I don't see how to manually override it so it takes my value.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2025 Laravel.io - All rights reserved.