Support the ongoing development of Laravel.io →
posted 8 years ago
Security

Short: Is there a way to generate a CSRF token in the controller (not in a view)?

Long: I have a web app that users stay logged in for long periods of time. CSRF tokens expire, so I have the script updating them every 10 minutes. Right now I've hacked it together by having a view that generates JSON, but that's ugly. And I now want to use the periodic refresh to include other data.

Last updated 3 years ago.
0

You have access to that token via the helper csrf_token() or if you have access to a request $request->session()->token().

0

Sign in to participate in this thread!

Eventy

Your banner here too?

AdamColton adamcolton Joined 12 May 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.

© 2025 Laravel.io - All rights reserved.