Skip to content

Instantly share code, notes, and snippets.

@jrmadsen67
jrmadsen67 / gist:bd0f9ad0ef1ed6bb594e
Last active February 15, 2022 08:41
Laravel Quick Tip: Handling CsrfToken Expiration gracefully
Quick tip for handling CSRF Token Expiration - common issue is when you use csrf protection is that if
a form sits there for a while (like a login form, but any the same) the csrf token in the form will
expire & throw a strange error.
Handling it is simple, and is a good lesson for dealing with other types of errors in a custom manner.
In Middleware you will see a file VerifyCsrfToken.php and be tempted to handle things there. DON'T!
Instead, look at your app/Exceptions/Handler.php, at the render($request, Exception $e) function.
All of your exceptions go through here, unless you have excluded them in the $dontReport array at the
@thinkt4nk
thinkt4nk / serializeObject.js
Created April 6, 2011 13:54
Serialize an object from jquery serialized array
$.fn.serializeToObject = function() {
var serial_array = this.serializeArray();
var serial_object = {};
$(serial_array).each(function() {
if( !serial_object[this.name] )
{
serial_object[this.name] = this.value;
}
});
return serial_object;