Skip to content
Advertisement

How to Set an Expiration Date after a Year in Laravel

I’m trying to make an investment website where I want to set an expiration date exactly after a year that the registration was made. Upon the registration, an initial deposit is required which is the one with the value “500” which is fixed on every registration. I want to use the created_at timestamp from my database table money_trade_deposits as the reference for the start date and calculate the expiration date based on that after a year and pass it on my laravel blade view. I’m new to laravel and I have no idea how to this.

This is my money_trade_deposits table and I wanna base the expiration date from the created_at date.
enter image description here

Or it it possible to add a new timestamp row which will automatically calculate the expiration date adter a year? Any help will be much appreciated. Thanks a lot!

Advertisement

Answer

Since the created_at is automatically casted as a Carbon instance in Laravel, you can calculate the expiration date one year after with the ->addYear() method.
Ex: $model->created_at->addYear()->toDateTimeString().
Reference: Carbon doc

User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement