代码之家  ›  专栏  ›  技术社区  ›  Yosef

Laravel-即使使用name属性也无法传递表单数据

  •  0
  • Yosef  · 技术社区  · 6 年前

    我有一个评论表单,我正试图提交评论和票证id,但由于某种原因,数据没有通过请求。我用的是 name="" 输入的属性。我试过把请求信息丢弃 dd($request->all()) csrf_token files=>null

    <form method="POST" action="{{ route('admin.returns.postComment') }}">
           {{ csrf_field() }}
           <input type="hidden" style="display: none;" name="rma_ticket_id" value="{{ $rma->rma_ticket_id }}" disabled>
           <div class="js-summernote" name="comment"></div>
           <div class="mt-3 clearfix">
                <button type="submit" class="btn btn-primary float-right">
                  <i class="fa fa-plus mr-1"></i> Post Comment
                </button>
    
               @if ($rma->status->name != "Closed")
                  <button type="button" class="btn btn-danger float-left">
                       <i class="fa fa-times mr-1"></i> Close
               </button>
               @endif
    
            </div>
    </form>
    

    /**
         * Post comment and notify the customer.
         *
         * @param Request $request
         * @return \Illuminate\Http\RedirectResponse
         */
        public function postComment(Request $request)
        {
            try {
    
                dd($request->all());
    
                $comment = RmaComments::create([
                    'user_id'       => Auth::user()->id,
                    'rma_ticket_id' => $request->input('rma_ticket_id'),
                    'name'          => Auth::user()->first_name.''.Auth::user()->last_name,
                    'comment'       => $request->input('comment'),
                ]);
    
                // TODO - add function to notify customer when message is posted.
    
                return redirect()->back()->with('success', 'Your comment has be submitted to the customer.');
    
            } catch (\Exception $e)
            {
                // return redirect()->back()->with('danger', 'There was a problem trying to post your comment.');
                return redirect()->back()->with('danger', $e->getMessage());
            }
        }
    

    路线:

    Route::post('/returns/postComment', 'Backend\RmaController@postComment')->name('admin.returns.postComment');
    
    0 回复  |  直到 6 年前