試試看。它來自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.'
);
}
由於這些自定義消息在僱員類中定義,它們只從這個類適用於輸入。你可以做同樣的公司類:
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的驗證。但無論如何,我希望這有助於!
這只是一種解決方法。也許Ardent不支持這個功能。 – 2014-09-22 20:15:51
我已經成功地研究了Ardent,除了上面的方法之外,我看不到一種方法來實現所需的功能(即不修改Ardent的原始源代碼) – 2014-09-23 13:07:02