dongtan3395 2015-07-24 08:03
浏览 36
已采纳

添加表单上的不匹配令牌laravel

I have this form to create a new article. User inputs everything correctly but i get a return of TokenMismatchException in VerifyCsrfToken.php line 53:. I saw another post saying that because i used the open form Tag it will already add this for me and to take it out. How do i take this out? or is there some other problem that im overlooking?

here is my controller

public function store( AddArticleController $request)
{
    $request= $request->all();
    $request['user_id']=Auth::id();
    Article::create($request->all());


    return redirect('/user');
}

and here is the html

<form class="form-horizontal" role="form" method="POST" action="{{ url('/article/add') }}">
                {!! Form::open(
                array(
                'class' => 'form',
                'novalidate' => 'novalidate',
                'files' => true)) !!}
                <div class = "form-group">
                    {!! Form::label('title','Title:', ['class' => 'col-md-4 control-label']) !!}
                    <div class="col-md-6">
                    {!! Form::text('title',null, ['class' => 'form-control']),  !!}

                    </div>
                </div>
                <div class = "form-group">
                    {!! Form::label('title','Image:', ['class' => 'col-md-4 control-label']) !!}
                    <div class="col-md-6">
                        {!! Form::file('image') !!}
                    </div>
                </div>
                <div class="form-group">
                    {!! Form::label('title','Type:', ['class' => 'col-md-4 control-label']) !!}
                    <div class="col-lg-1">
                    {!! Form::select('type', array('select' => 'select','fashion' => 'Fashion', 'music' => 'Music', 'dance' => 'Dance', 'event' => 'Event'))!!}
                    </div>

                </div>
                <div class = "form-group">
                    {!! Form::label('body','Comment:', ['class' => 'col-md-4 control-label']) !!}
                    <div class="col-md-6">
                        {!! Form::textarea('body',null, ['class' => 'form-control']) !!}
                    </div>
                </div>
                <div class = "form-group">
                    {!! Form::label('body',' ', ['class' => 'col-md-4 control-label']) !!}
                        <div class="col-md-6">
                    {!! Form:: submit('Sumbit', ['class' => 'btn btn-primary form-control']) !!}
                        </div>
                    </div>
                {!! Form::close() !!}
            </form>
  • 写回答

2条回答 默认 最新

  • dter8514 2015-07-24 09:19
    关注

    First, which version of Laravel do you use?

    The Laravel's HTML Helper has been removed in the version 5 of Laravel and is now not updated. If you still want to use this helper I recommend you to use the version updated by the community https://github.com/LaravelCollective/html.

    For your problem, if you don't use the helper, you need to add the token manualy by adding {!! csrf_token() !!} in your form. You can find more information in the documentation: http://laravel.com/docs/5.1/routing#csrf-protection

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 求TYPCE母转母转接头24PIN线路板图
  • ¥100 国外网络搭建,有偿交流
  • ¥15 高价求中通快递查询接口
  • ¥15 解决一个加好友限制问题 或者有好的方案
  • ¥15 急matlab编程仿真二阶震荡系统
  • ¥20 TEC-9的数据通路实验
  • ¥15 ue5 .3之前好好的现在只要是激活关卡就会崩溃
  • ¥50 MATLAB实现圆柱体容器内球形颗粒堆积
  • ¥15 python如何将动态的多个子列表,拼接后进行集合的交集
  • ¥20 vitis-ai量化基于pytorch框架下的yolov5模型