dousunle5801
2018-06-22 11:31
浏览 320
已采纳

@csrf在Laravel 5.4中不起作用

I am following this tutorial on Laravel and I've noticed that I cannot use the @csrf command, but others can use it effectively. But, I can use the {{ csrf_field() }} for the csrf token. I would like to know the reason why. Thanks.

Here's my screenshot on using the @csrf command: Image here

Here's my index.blade.php

       <form action="{{ route('contact.store') }}" method="post">

            @csrf

            <div class="col-md-6 mb-3">
                <label for="username">Username:</label>
                <input class="form-control" type="text" name="name" id="username" placeholder="Username | Email | Phone Number" required>
                <div class="invalid-feedback">
                    Please provide a username
                </div>
            </div>

            <div class="col-md-6 mb-3">
                <label for="password">Password:</label>
                <input class="form-control" type="password" name="name" id="password" placeholder="" required>
                <div class="invalid-feedback">
                    Please provide a password
                </div>
            </div>

            <div class="col-md-6 mb-3">
                <input type="submit">
            </div>
        </form>

图片转代码服务由CSDN问答提供 功能建议

我在Laravel上关注本教程,我注意到我不能使用@csrf命令,但其他人可以 有效地使用它。 但是,我可以使用{{csrf_field()}}作为csrf标记。 我想知道原因。 谢谢。

这是我使用@csrf命令的截图:这里的图片

这是我的index.blade.php

 &lt; form action =“{{route('  contact.store')}}“method =”post“&gt; 
 
 @csrf 
 
&lt; div class =”col-md-6 mb-3“&gt; 
&lt; label for =”  username“&gt;用户名:&lt; / label&gt; 
&lt; input class =”form-control“type =”text“name =”name“id =”username“placeholder =”Username | Email | Phone Number“required&gt;  
&lt; div class =“invalid-feedback”&gt; 
请提供用户名
&lt; / div&gt; 
&lt; / div&gt; 
 
&lt; div class =“col-md-6 mb  -3“&gt; 
&lt; label for =”password“&gt;密码:&lt; / label&gt; 
&lt; input class =”form-control“type =”password“name =”name“id =”password  “placeholder =”“required&gt; 
&lt; div class =”invalid-fee  dback“&gt; 
请提供密码
&lt; / div&gt; 
&lt; / div&gt; 
 
&lt; div class =”col-md-6 mb-3“&gt; 
&lt;输入 type =“submit”&gt; 
&lt; / div&gt; 
&lt; / form&gt; 
   
 
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

3条回答 默认 最新

  • doumibi6899 2018-06-22 11:34
    已采纳

    As far as I know, there is no @csrf in 5.4, you must use

    {{ csrf_field() }}
    

    Instead, @csrf is available in laravel 5.6

    打赏 评论
  • douchun1900 2018-06-22 11:34

    @csrf argument came to blade with 5.6

    you need to use csrf_field() method instead @csrf

    for more information check out the docs

    打赏 评论
  • dousao8152 2018-06-22 11:44

    Laravel 5.4 only available refer to this link https://laravel.com/docs/5.4/csrf

    {{ csrf_field() }}
    

    And Laravel 5.6 available refer to this link https://laravel.com/docs/5.6/csrf

    @csrf
    
    打赏 评论

相关推荐 更多相似问题