在我的网站上,注册用户可以创建帖子。帖子包括标题,类型,子类型,cover_image和正文。最近我包括标题,类型和子类型,这是创建错误的原因。在我包含这些列之前,它工作正常。单击“创建发布”按钮时,它会向我显示以下错误:
BadMethodCallException
Method Illuminate\Validation\Validator::validateRquired does not exist.
不确定为什么它会出现此错误,我的验证似乎没问题。
以下是我的观点:
<section class="row new-post">
<div class="col-md-6 col-md-offset-3">
<header><h3>What do you have to say</h3></header>
<form action="{{ route('postcreate') }}" method="post" enctype="multipart/form-data">
<div class="form-group">
<label for="title">Title</label>
<input type="text" class="form-control" name="title">
</div>
<div class="form-group">
<label for="type">Type</label>
<select name="type" class="form-control">
<option value="volvo">Volvo</option>
</select>
</div>
<div class="form-group">
<label for="subtype">Subtype</label>
<input type="text" class="form-control" name="subtype">
</div>
<div class="form-group">
<label for="cover_image">Upload Image</label>
<input type="file" name="cover_image" class="form-control" id="cover_image">
</div>
<div class="form-group">
<textarea class="form-control" name="body" rows="5" placeholder="your post"></textarea>
</div>
<button type="submit" class="btn btn-primary">Create post</button>
<input type="hidden" name="_token" value="{{ csrf_token() }}">
</form>
</div>
</section>
这是我的postController.php方法:
public function postCreatePost(Request $request){
$this->validate($request, [
'title' => 'rquired',
'type' => 'required',
'subtype' => 'required',
'body' => 'required',
'cover_image' => 'required|image||nullable|max:1999'
]);
$filenameWithExt = $request->file('cover_image')->getClientOriginalName();
$filename = pathinfo($filenameWithExt, PATHINFO_FILENAME);
$extension = $request->file('cover_image')->getClientOriginalExtension();
$fileNameToStore = $filename . '_' . time() . '.' . $extension;
$path = $request->file('cover_image')->storeAs('public/cover_images', $fileNameToStore);
$post = new Post();
$post->title = $request['title'];
$post->type = $request['type'];
$post->subtype = $request['subtype'];
$post->body = $request['body'];
$post->cover_image = $fileNameToStore;
$message = 'There was an error';
if($request->user()->posts($post)->save($post)){; //points here
$message = 'post successfully created';
}
return redirect()->route('dashboard')->with(['message' => $message]);
}
答案 0 :(得分:1)
方法Illuminate \ Validation \ Validator :: validateRquired不存在。
上面的例外说明了一切 - 你的代码中有拼写错误。这一行:
'title' => 'rquired',
应该说:
'title' => 'required',