试试这个。它来自 GitHub 上的文档。我从未与 Ardent 合作过,但它实际上有相当不错的文章。
class Employee extends \LaravelBook\Ardent\Ardent {
public static $rules = array(
'name' => 'Required|Alpha_Dash'
);
public static $customMessages = array(
'required' => 'The Employee :attribute field is required.',
'alpha_dash' => 'The Employee :attribute field must be Letters and Dashes only.'
);
}
由于这些自定义消息是在Employees 类中定义的,因此它们仅适用于此类的输入。您可以对 Company 类执行相同的操作:
class Company extends \LaravelBook\Ardent\Ardent {
public static $rules = array(
'name' => 'Required|Alpha_Dash'
);
public static $customMessages = array(
'required' => 'The Company :attribute field is required.',
'alpha_dash' => 'The Company :attribute field must be Letters and Dashes only.'
);
}
我认为这应该有效。但是,我没有任何方法可以测试它。另一种选择是使用自定义规则,例如
'name' => 'Employee_Required|Employee_Aplha_Dash'
并在 Laravel 的验证中定义这些。但无论如何,我希望这会有所帮助!