【发布时间】:2017-09-27 08:07:10
【问题描述】:
<form method="post" action="{{action('PLAYERController@update', $ply->reg_no)}}">
{{csrf_field()}}
在自定义验证中获取方法不允许异常返回错误。尝试在 csrf 字段中提及 PUT、PATCH 和 DELETE。还是不行。
更新
使用 post 作为表单方法。使用 method_field('POST')。没有为更新函数定义 get 方法。如果我从错误页面返回到表单页面并按刷新,则验证消息将按原样显示。
更新 2
Validator::extend('check_sold_amount', function($attribute, $value, $parameters, $validator) {
if(($value%5000)==0)
{
return true;
}
return false;
});
}
更新 3
控制器代码
public function update(Request $request, $reg_no)
{
//
$this->validate($request, [
'sold_amount' => 'required|check_sold_amount',
'sold_to_team'=>'required'
]);
$ply = Player::find($reg_no);
$ply->sold_amount = $request->get('sold_amount');
$ply->sold_to_team = $request->get('sold_to_team');
$team_name=$ply->sold_to_team;
$team=Team::find($team_name);
if($ply->category=='indian')
{
$team->indian_players=$team->indian_players+1;
}
else {
$team->foreign_players=$team->foreign_players+1;
}
$team->balance=$team->balance-$ply->sold_amount;
$ply->save();
$team->save();
//return view('player.index');
}
【问题讨论】:
-
提供路由和刀片代码
标签: laravel