douluoxiao2286 2017-10-11 02:13
浏览 38
已采纳

在Laravel中使用dd转储POST时缺少表单值

I have a VERY simple test app based on Laracasts which is not submitting data via in a very simple view and returns only the CSRF token and no data when submitting. I'm unclear what step I've missed...

My route is:

Route::post('/posts', 'PostsController@store');

My form in my View is:

  <form method="POST" action="/posts">
    {{ csrf_field() }}
    <input type="hidden" id="mytest" value="denis">
    <div class="form-group">
      <label for="title">Title</label>
      <input type="text" class="form-control" id="title" placeholder="title">
    </div>
    <div class="form-group">
      <label for="body">Body</label>
      <textarea class="form-control" id="body" placeholder="Body"></textarea>
    </div>
  <button type="submit" class="btn btn-primary">Publish</button>
  </form>

My PostsController is:

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class PostsController extends Controller
{
    public function store()
    {
      dd(request()->all());
    }
}

Posting of my form results in this:

array:1 [
    "_token" => "43xJev3Xo2hh88r0IoHRJpoNhn4w3eVztgxbpNAY"
]

And NOT something like this (which is the problem):

array:1 [
    "_token" => "43xJev3Xo2hh88r0IoHRJpoNhn4w3eVztgxbpNAY"
    "title" => "My test post title"
    "body" => "My test body value"
]
  • 写回答

2条回答 默认 最新

  • dongmo1708 2017-10-11 02:14
    关注

    You forgot the "name" attribute on your input and textarea.

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

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog