简体   繁体   English

Laravel 5.4 csrf_field()无法正常工作

[英]Laravel 5.4 csrf_field() not working

I am trying to make a simple view and I want to be able to make a post request. 我正在尝试做一个简单的视图,我希望能够发出一个发布请求。 I need to generate a csrf token and this is the html view that I have: 我需要生成一个csrf令牌,这是我拥有的html视图:

<form method="POST" action="/formsubmit">
{!! csrf_field() !!}
First Name: <br>
<input type="text" name="firstname"><br>
Last Name:<br>s
<input type="text" name="lastname"><br>
<input type="submit" name="Submit"><br>   
</form>

This is my route: 这是我的路线:

Route::get('form', function(){
return view('form');
});

Route::post('formsubmit',function(){
return 'Form Posted.';
});
Auth::routes();

This is what happens when I try the url: 这是我尝试网址时发生的情况:

在此处输入图片说明

As you can see, it just prints the name of the function, but the function is not ever called and the hidden field is not being generated. 如您所见,它只是打印函数的名称,但从未调用该函数,也不会生成隐藏字段。 Is there something that needs to be done in order to make it work? 为了使其正常工作需要做些什么吗?

Blade's templating language will only get interpreted in a file with a .blade.php extension. Blade的模板语言仅在扩展名为.blade.php的文件中进行解释。 One with just a .php extension will work with Laravel, but you won't have any Blade functionality. Laravel只能使用.php扩展名,但您将没有任何Blade功能。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM