이것은 제가 숙련공 5.0 콘솔 명령에서 인수의 유효성을 검사하기 위해 방금 사용한 것입니다. 이것은 fire()
방법입니다 : 이것은 @tfont
의 대답에 확장이
// Create the validator.
$validator = Validator::make(
$this->argument(),
['field1' => 'required|other|rules']
);
// Validate the arguments.
if ($validator->fails())
{
// Failed validation.
// Each failed field will have one or more messages.
foreach($validator->messages()->getMessages() as $field_name => $messages) {
// Go through each message for this field.
foreach($messages AS $message) {
$this->error($field_name . ': ' . $message);
}
}
// Indicate the command has failed.
return 1;
}
당신은 메시지가 전송되는 위치를 변경해야 할 수도 있습니다
($this->error()
)이 명령은로 실행되고 있지 않은 경우 콘솔 명령, 즉 CLI, 명령 행.
내 방법을 말해 줄 수 있습니까? 내가보기에 그들을 전달하고 싶지 않아 –
귀하의 컨트롤러에서 유효성 검사 메시지를 반복 할 수 있습니다 :'foreach ($ validation-> messages() $ message) {/ ** /}' – Dwight