Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

hacker1122's avatar

Delete a Row in a Table [Laravel 5.4]

Hi. I have a system with points. After a user submit a charge with stripe, Laravel crates in the DB a Row in a Table ( named 'orders') which contains: created_at, points associated with that product, product_name, user_id.

After this all i have to do to display the user points is to sum() the orders for that particular user_id. The problem is: Now i want that, the points expires after 9 month if you are not using it to purchase a product with that points.

So, i think that i have to create a cron job maybe to check if the 'created_at + 9 month' is exceeded and delete that row, but i don't know how to do that.

Maybe is there a way to create another column in the DB in the Migration, that display 'created_at + 9 month' in orders from the start. Maybe using Carbon to add Mounth to a $table->timestamp

Thanks for the attention, and excuse me for my english :)

0 likes
5 replies
hacker1122's avatar

@berkapavel And for populate the expiration row what i can do? I can't do all in the migration right? I need to tell somewhere the cose to populate the date every time an order is created ... How i can do? In the Model maybe? Sry but i'm somewhat new to Laravel.

berkapavel's avatar

when you create new order (wherever you are doing it) you just call carbon appropriate function and save it to the table

Please or to participate in this conversation.