Answer the question
In order to leave comments, you need to log in
How to change a record in the database when a certain date is reached?
I want to enable monthly subscription on a website (laravel 8).
I have a table in the database that defines the subscription expiration date and the subscription status (1 or 0).
The subscription status determines access to the content.
How can I write a function, and what should I use so that when a certain date is reached, the subscription status changes to 0 in the database?
Answer the question
In order to leave comments, you need to log in
Databases don't work that way.
In this case, the status is redundant, and it can be removed from the database
. Thus, nothing will need to be changed.
As FanatPHP wrote , the status field is redundant,
if you need to have the current subscription status, you can create a view:
create view subscriptions_status as select
id, user_id, created_at, end_at,
case when end_at > now() then 1 else 0 end active
from subscriptions;
select * from subscriptions_status;
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question