I want to use form tag in laravel framework as below
<form method="post" action="<?php echo 'SongController@savenew';?>">
but after submitting it gives me an error
TokenMismatchException in VerifyCsrfToken.php line 53:
You need to include the CSRF token in your form like this:
Laravel makes it easy to protect your application from cross-site request forgeries. Cross-site request forgeries are a type of malicious exploit whereby unauthorized commands are performed on behalf of the authenticated user.
Laravel automatically generates a CSRF "token" for each active user session managed by the application. This token is used to verify that the authenticated user is the one actually making the requests to the application. To generate a hidden input field _token containing the CSRF token, you may use the csrf_field helper function:
<input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
You need to use Laravel's form builder. Because it requires a CSRF(Cross-site Request Forgery) token, but when you create the form manually the token isn't added to the html, you have to add the token manually ie. <input type="hidden" name="_token" value="<?php echo csrf_token(); ?>">
, but it is a little safer to use Laravel's standard:
<?= Form::open(['controller' => 'SongController@savenew', 'method' => 'POST']); ?>
<?= Form::close(); ?>
If you're using blade(Recommended):
{!! Form::open(['controller' => 'SongController@savenew', 'method' => 'POST']) !!}
{!! Form::close(); !!}
Laravel form request always required csrf token
Used
<Form method="post" action="">
{{ csrf_field() }}
</Form>