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

juliouslara's avatar

Store in session the last value of the column updated_at

Hello,

I am new in laravel, I just want to know how to store the last value of updated_at column in session after I update the record and echo out in view. for example: Last Login: 2days ago. thanks!

0 likes
3 replies
eduphp8's avatar

Hi, the simplest way is to just make a new column in the users table

$table->dateTime('last_login')

and update it on every successful login ;)

juliouslara's avatar

Hi swalker, I already did that. every time the user logged in, I update the updated_at column on my table. but I want to display the date before I update the updated_at column.

what in my mind is when the user logged in there is a session that will store the value of updated_at column value before I update the value of the column. so I can echo out the last value of the updated_at column. but I don't know how to do that in laravel. thanks for the reply :)

eduphp8's avatar

You just want to display it once right?

You can redirect from your login with a message

redirect()->to('/home')->withMessage("Last login {$lastLogin->diffForHumans()}");

Or simply flash a session message

$request->session()->flash('message', "Last login {$lastLogin->diffForHumans()}")j

Then you can display it in your view

@if(session('message'))
    {{session('message')}}
@endif

Please or to participate in this conversation.