How to Use CSRF Token in Laravel?

Hello friends, today I will tell you about csrf token in laravel. Csrf token is a very important part in laravel. Its full name is Cross-site request forgery. It is used by puspose of security. It is used when we submit the form So here we use csrf token. How to use it? Your code of csrf is given below. You can use csrf token in any version of laravel.Such as Laravel 7, Laravel 6, Laravel 5.8, Laravel 5.7 etc.

In form we can do CSRF in 2 ways.

No.1 :- {{ csrf_field() }}
No. 2 :- <input type=”hidden” name=”_token” value=”<?php echo csrf_token(); ?>”>

it is first method use in form.

<form method = "POST" action="{{url('Saveblog')}}">
{{ csrf_field() }}
...
</form>

it is second method use in form.

<form method = "POST" action="{{url('Saveblog')}}">
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
...
</form>