Laravel 5.7 验证仍然无效
Laravel 5.7 validation works still not
我已经问过关于 Laravel 5.7 验证的问题,但它仍然不能正常工作。发送内容时根本不执行验证。
public function store(Request $request)
{
$data=$request->all();
$validator = Validator::make($data, [
'first_name' => 'alpha|min:2|max:30',
]);
}
提前致谢
我根本没有看到你的验证码。
在 laravel
中有两种实现验证的方法
- 表单请求验证
- 控制器方法中的验证
请添加一个,然后重试
if your are not using form validation then maybe it will be helpful for you.
I add validator example in your code, you can try it
maybe your problem will resolve
public function update(Request $request, Player $player)
{
//example validation
$validator = Validator::make($request->all(), [
'id' => 'required|integer', //put your fields
'text' => 'required|string' //put your fields
]);
if ($validator->fails()){
return "Invalid Data";
}
if(Auth::check()){
$playerUpdate = Player::where('id', $player->id)
->update([
'first_name' => $request->input('fist_name'),
'last_name' => $request->input('last_name')
]);
if($playerUpdate){
return redirect()->route('players.show', ['player'=> $player->id])
->with('success' , 'player foo');
}
}
return back()->withInput()->with('errors', 'Foo error');
}
我已经问过关于 Laravel 5.7 验证的问题,但它仍然不能正常工作。发送内容时根本不执行验证。
public function store(Request $request)
{
$data=$request->all();
$validator = Validator::make($data, [
'first_name' => 'alpha|min:2|max:30',
]);
}
提前致谢
我根本没有看到你的验证码。 在 laravel
中有两种实现验证的方法- 表单请求验证
- 控制器方法中的验证
请添加一个,然后重试
if your are not using form validation then maybe it will be helpful for you. I add validator example in your code, you can try it maybe your problem will resolve
public function update(Request $request, Player $player)
{
//example validation
$validator = Validator::make($request->all(), [
'id' => 'required|integer', //put your fields
'text' => 'required|string' //put your fields
]);
if ($validator->fails()){
return "Invalid Data";
}
if(Auth::check()){
$playerUpdate = Player::where('id', $player->id)
->update([
'first_name' => $request->input('fist_name'),
'last_name' => $request->input('last_name')
]);
if($playerUpdate){
return redirect()->route('players.show', ['player'=> $player->id])
->with('success' , 'player foo');
}
}
return back()->withInput()->with('errors', 'Foo error');
}