我想更新一个常见问题表格。但我收到此错误。
SQLSTATE [42S22]:找不到列:1054“字段列表”中的未知列“ _method”(SQL:更新
faqs
设置_method
= PUT,_token
= Kz2Wkgd44UA3nOVzmE8PhCGH66ywP296UqUQR8m6,{ {1}} = q,title
= q,body
。faqs
= 2019-09-15 18:55:06其中updated_at
。faqs
= 1和user_id
。faqs
不为空)
FaqController.php
user_id
edit.blade.php
public function update(FaqRequest $request, Faq $faq)
{
auth()->user()->faq()->update($request->all());
return redirect()->route('faq.index');
}
User.php
<form action="{{ route('faq.update', $faq->id ) }}" method="post">
@method('PUT')
@csrf
@include('errors.validate')
<div class="form-group">
<label for="title">title</label>
<input type="text" class="form-control col-md-3" id="title" name="title" value="{{ old('title') ? : $faq->title }}">
</div>
<div class="form-group">
<label for="body">body</label>
<textarea class="form-control" rows="10" id="body" name="body">{{ old('body') ? : $faq->body }}</textarea>
</div>
<div class="form-group">
<button type="submit" class="btn btn-primary">save</button>
</div>
</form>
Faq.php
public function faq()
{
return $this->hasMany(Faq::class);
}
答案 0 :(得分:0)
您可以使用$request->except(...)
,例如通过将功能修改为
public function update(FaqRequest $request, Faq $faq)
{
auth()->user()->faq()->update($request->except('_method', '_token'));
return redirect()->route('faq.index');
}