0
我有一個自定義的驗證,見下文(簡體)Laravel 5.2 |設定Calculcated值自定義屬性的飛行從未更換
表單請求
public function rules()
{
return [
'amount' => 'required|numeric|max_invest:10000'
];
}
public function messages()
{
return [
'max_invest' => 'You can invest max :mi' // I want to set :mi on the fly
];
}
驗證
public function validateMaxInvestment($attribute, $value, $parameters, $validator)
{
$this->setAttributeNames(['mi' => intval($parameters[0] - $value)]); // Try to set the attribute mi on the fly
return $value < $parameters[0];
}
我沒註冊驗證器在我的服務提供商的啓動方法中,如下所示:
$this->app['validator']->extend('maxInvestment',
'[email protected]');
問題
驗證器工作正常,但消息我得到住宿:
你可以投資最大:mi
調用setAttributeNames
不生效的方法。