xxxxxxxxxx
<input type="hidden" name="_token" value="{{ csrf_token() }}">
xxxxxxxxxx
<!-- Add this to header -->
<meta name="csrf-token" content="{{ csrf_token() }}">
<!-- Add this to script -->
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
</script>
xxxxxxxxxx
<form method="POST" action="/profile">
@csrf
<!-- Equivalent to... -->
<input type="hidden" name="_token" value="{{ csrf_token() }}" />
</form>
xxxxxxxxxx
Adding CSRF in Laravel:
3 ways we can add CSRF in Laravel.
@csrf OR {{ csrf_field() }} OR <input type="hidden" name="_token" value="{{ csrf_token() }}">
<form method="POST"<
// Generate hidden input field
@csrf
OR
{{ csrf_field() }}
OR
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
xxxxxxxxxx
<form method="POST" action="/profile">
@csrf
<input name="name">
<button type="submit">send</button>
</form>