2016-07-27 2 views
3

등록 시스템을 가지고 있으며 유효성 검사 오류를 표시해야합니다. Semantic-UI Framework를 사용하고 있기 때문에 대부분의 유효성 검사가 JavaScript에 의해 검사됩니다. 하지만 실제로 JavaScript에서 표시 할 수없는 두 가지 사용자 지정 유효성 검사 규칙이 있으므로이 두 오류 메시지 중 어떤 것이 있는지 확인하고 올바른 오류 메시지를 플래시해야합니다. 여기 유효성 검사 오류를 반복하고 올바른 내용을 표시하십시오. - Laravel 5.2

유효성 검사 내 등록 기능입니다 :

public function postRegister (Request $request) { 

     $validator = Validator::make($request->all(), [ 
      'username' => 'unique:users', 
      'email' => 'unique:users', 
      'password' => '', 
     ]); 

     if ($validator->fails()) { 
      flash()->error('Error', 'Either your username or email is already take. Please choose a different one.'); 
      return back(); 
     } 

     // Create the user in the Database. 
     User::create([ 
      'email' => $request->input('email'), 
      'username' => $request->input('username'), 
      'password' => bcrypt($request->input('password')), 
      'verified' => 0, 
     ]); 

     // Flash a info message saying you need to confirm your email. 
     flash()->overlay('Info', 'You have successfully registered. Please confirm your email address in your inbox.'); 

     return redirect()->back(); 

당신이 두 개의 사용자 지정 오류 메시지가 있으며, 사용자가 그 중 하나 잘못 들어간 경우, 내 달콤한 경고 모달을 깜박 볼 수 있듯이 그 메시지와 함께.

어떻게하면 오류 메시지를 반복해서보고 어떤 오류가 발생하는지 확인하고 해당 오류에 대한 특정 플래시 메시지를 표시 할 수 있습니까?

$messages = $validator->errors(); 
//Determining If Messages Exist For A Field 
if ($messages->has('username')) { 
    //Show custom message 
} 
if ($messages->has('email')) { 
    //Show custom message 
} 
+0

당신은 단순히 $ validator-> 메시지() –

답변

2

모든 검증 오류의 배열을 검색하려면, 당신은 errors 방법을 사용할 수 있습니다. 그거야.
+0

감사를 구문 분석 할 수 있습니다 : – David

+0

당신은 환영합니다. –