這裏是我的視圖代碼:laravel請求驗證問題
<!-- form.blade.php -->
<form class="form-horizontal" action="{{ isset($article) ? URL('console/articles/'.$article->id) : URL('console/articles') }}" method="POST">
@if (isset($article))
<input name="_method" type="hidden" value="PUT">
@endif
@unless (empty($errors->first()))
<div class="alert alert-danger alert-dismissible" role="alert">
<button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button>
...
</div>
@endunless
<input type="hidden" name="_token" value="{{ csrf_token() }}">
<div class="form-group {{ $errors->has('title') ? 'has-error' : '' }}">
<label for="article_title" class="col-sm-2 control-label">...</label>
<div class="col-sm-8">
<input type="text" name="article[title]" id="article_title" class="form-control" placeholder="..." value="{{isset($article) ? $article->title : old('title')}}">
{!! $errors->first('title', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group {{ $errors->has('body') ? 'has-error' : '' }}">
<label for="article_body" class="col-sm-2 control-label">...</label>
<div class="col-sm-8">
<textarea name="article[body]" id="article_body" cols="30" rows="10" class="form-control">{{isset($article) ? $article->body : old('body')}}</textarea>
{!! $errors->first('body', '<p class="help-block">:message</p>') !!}
</div>
</div>
<div class="form-group">
<div class="col-sm-offset-2 col-sm-8">
<button type="submit" class="btn btn-success">...</button>
</div>
</div>
</form>
,並要求驗證:
// StoreArticleRequest.php
// ...
public function rules()
{
switch ($this->method()) {
case 'GET':
case 'DELETE': {
return [];
}
case 'POST': {
return [
'article.title' => 'required|unique:articles|max:255',
'article.body' => 'required'
];
}
case 'PUT':
case 'PATCH': {
return [
'article.title' => 'required|unique:articles,title,'.Route::input('articles').'|max:255',
'article.body' => 'required'
];
}
default:
break;
}
return [];
}
// ...
後發送POST請求創建方法,提高
SQLSTATE [42S22 ]:未找到列:1054未知列'article.title' in'where clause'
SQLSTATE [42S22]:未找到列:1054'where子句'中的未知列'article.title' (SQL:select count(*)as
articles
wherearticle
。title
=試驗)
更新
Here`s我的控制器的代碼:
// ArticlesController.php
// ...
public function store(StoreArticleRequest $request)
{
$article = new Article($request->input('article'));
if ($article->save()) {
return redirect('console/articles')->with('success', '...');
} else {
return redirect()->back()->withInput();
}
}
// ...
public function update(StoreArticleRequest $request, $id)
{
$article = Article::find($id);
if ($article->update($request->input('article'))) {
return redirect('console/articles')->with('success', '...');
} else {
return redirect()->back()->withInput();
}
}
// ...
它清楚地說明什麼問題'未知列'article.title''意味着你沒有名爲'article.title'的列,因爲它應該是文章** s **。title – Gal
你能顯示控制器存儲方法的代碼? –
刪除雙重代碼 –