Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

You're refetching Auth::user in the second call and as such your changes in the first line go away.

$user = Auth::user()->expires_at = strtotime("+". $packDuration." months",time());
$user->save();

or just plain:

Auth::user()->expires_at = strtotime("+". $packDuration." months",time())->save();
Last updated 2 years ago.
0

Hi thank you for your reply, but i dont tkink this can work !

In the both examples you are calling the save method from the strtotime function not from the model, i tried and "call to a member function save() on a non-object"

In my first example i show you "expires_at" but its not the only things i save !

$packDuration = Pack::find($buy_info['pack_id'])->duration;
Auth::user()->pack_id = $buy_info["pack_id"];
Auth::user()->expires_at = strtotime("+". $packDuration." months",time());
Auth::user()->save();

My user pack_id is well saved in DB and session. :/

My expires_at is fillable in my model.

Last updated 2 years ago.
0
Auth::user()->expires_at = strtotime("+". $packDuration." months",time());

Doesn't this need to be like:

Auth::user()->expires_at = date('Y-m-d H:i:s', strtotime("+". $packDuration." months",time()));
Last updated 2 years ago.
0

Thank you very much.

Timestamps and dates has always been my nightmare. I don't get why i have to put a date in a timestamp column but ok.

Thank you again you saved my day. =)

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

DrimZ drimz Joined 21 Apr 2014

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.

© 2024 Laravel.io - All rights reserved.