I'm building a mobile app and when a CSRF token isn't present I want to return an error in JSON instead of it returning the "TokenMismatchException" Html page.
Is there anyway to do this easily without adjusting the library code?
I'm building a mobile app and when a CSRF token isn't present I want to return an error in JSON instead of it returning the "TokenMismatchException" Html page.
Is there anyway to do this easily without adjusting the library code?
You can create your own custom responses and make one for TokenMismatchException
So you do that in the Exceptions/Handler.php
file. Something like;
public function render($request, Exception $e)
{
if($e instanceof TokenMismatchException)
{
return json(......
}
I think you might also need to include in the use statement;
use Illuminate\Session\TokenMismatchException as TokenMismatchException;