it's all there in the docs...
have a look at laravel from scratch series on this site... it's free.
you need {{ csrf_field() }} somewhere in your form
but this will only work if your html code is in a blade file.
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hello i just started learn PHP and Laravel I created simple html post page and simple Route to see entered values. And now i have Error with Token. I know i must somehow write {{ csrf_token() }} but where and how i dont known.
HTML Code:
<body>
<form action="/comments" method="POST">
Name:
<input type="text" name="name" /><br />
Comment:<br />
<textarea name="text"></textarea>
<!--<input type="hidden" name="_method" value="PUT">-->
<br />
<input type="submit" value="Pievienot"/>
</form>
</body>
Simple ROUTE:
Route::post('/comments', function ()
{
print_r($_POST);
});
Thanks Alot. I Finished with my question. Solution: I created form.blade.php View and inserted the hidden" value="{{ csrf_token() } in my form.
<!DOCTYPE html>
<html lang="en">
<head>
<title></title>
<meta name="" content="">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
</head>
<body>
<form action="/comments" method="POST">
<input name="_token" type="hidden" value="{{ csrf_token() }}"/>
Name::
<input type="text" name="name" /><br />
Comments:<br />
<textarea name="text"></textarea>
<!--<input type="hidden" name="_method" value="PUT">-->
<br />
<input type="submit" value="Pievienot"/>
</form>
</body>
</html>
And aCreated a New Route form to View it:
Routes:
Route::get('/comment', function () {
return view('form');
});
Route::post('/comments', function ()
{
print_r($_POST);
});
Please or to participate in this conversation.