Answer the question
In order to leave comments, you need to log in
How to add month to timestamps value in database to renew subscription?
In the Laravel project, I have a Subscriptions table that contains the following data:
id ; user_id ; end_date ; status; creation_date
On the button to renew the subscription, you need to add a month to end_date, withdraw money from the user's account and replace this entry in db.
Here is the function of this button:
public function buysubs(Request $request)
{
$amount = 100;
$user_id = Auth::id();
$permission = Permission::where('user_id', $user_id)->get()->first();
$user_balance = Balance::where('user_id', $user_id)->get()->first();
$Subscriptions = Subscription::where('user_id', $user_id)->get()->first();
$enddate = Subscription::where('user_id', $user_id)->first('end_date');
if (isset($user_balance->balance) && $user_balance->balance < '100') {
echo 'нет деняг';
}
if (!$Subscriptions) //отображается кнопка "купить подписку"
{
$Subscriptions = new Subscription();
$Subscriptions->user_id = $user_id;
$Subscriptions->creation_date = date("Y-m-d H:i:s");
$Subscriptions->end_date = date("Y-m-d H:i:s", strtotime("+1 month"));
$Subscriptions->status = '1';
$Subscriptions->save();
} // покупка подписки вроде работает
else ($Subscriptions->end_date > date("Y-m-d H:i:s"))
{
//???
$enddate = //???
$Subscriptions->status = '1';
$Subscriptions->save();
$enddate->save();
}
$user_balance->balance -= $amount;
$transaction = Transaction::create ([
'user_id' => $user_id,
'amount' => '-100',
'description' => 'Подписка на курс'
]);
$user_balance->save();
return view('dashboard', ['Subscriptions' => $Subscriptions], ['permission' => $permission]);
}
Answer the question
In order to leave comments, you need to log in
$Subscriptions->end_date = date("Y-m-d H:i:s", strtotime($Subscriptions->end_date . " +1 month"));
$subscription->save();
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question