Simply Create a meta
tag containing CSRF token,
<meta name="csrf-token" content="{{ csrf_token() }}">
Once you have created the meta tag, you can instruct a library like jQuery to add the token to all request headers. This provides simple, convenient CSRF protection for your AJAX based applications:
$.ajaxSetup({ headers: { 'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content') } });
Ajax CSRF Token verification
we do not need to manually verify the CSRF token in ajax request, The VerifyCsrfToken
middleware, which is included in the web middleware group will check for the X-CSRF-TOKEN request header automatically for us
X-XSRF-TOKEN
Laravel also stores the CSRF token in a XSRF-TOKEN
cookie. You can use the cookie value to set the X-XSRF-TOKEN
request header. Some JavaScript frameworks, do this automatically for you. It is unlikely that you will need to use this value manually.
Be the first one to write a response :(
{{ reply.member.name }} - {{ reply.created_at_human_readable }}