2017-12-24 18 views
0

그래서 내 입력 양식을 확인하여 작동 여부를 테스트 할 수 있도록 입력 양식에 대한 유효성 검사를하고 싶었 기 때문에 내 컨트롤러에서 사용하고 있습니다.laravel required inputs

$Message = [ 
     'required' => 'This input is required', 
    ]; 
    $validator = Validator::make($request->all(), [ 
     'name' => 'required', 
     'email' => 'required', 
     'password' => 'required', 
     'UserName' => 'required', 
     'Phone' => 'required', 
     'SSN' => 'required', 
     'SDT' => 'required', 
     'Country' => 'required', 
     'InsuranceAmount' => 'required', 
     'City' => 'required', 
     'Location' => 'required' 
    ], $Message); 

    if ($validator->fails()) { 


     return redirect('/admin/users/create') 
      ->withErrors($validator) 
      ->withInput(); 
    } 

    $user = new User; 
    $user->name = Input::get('name'); 
    $user->email = Input::get('email'); 
    $user->password = bcrypt(Input::get('password')); 
    $user->UserName = input::get('UserName'); 
    $user->Phone = input::get('Phone'); 
    $user->SSN = input::get('SSN'); 
    $user->SDT = input::get('SDT'); 
    $user->Country = input::get('Country'); 
    $user->City = input::get('City'); 
    $user->Location = input::get('Location'); 
    $user->save(); 
    return Redirect::to('/admin/users')->with('message', 'User Created'); 

오류가 없다면 사용자 목록으로 리디렉션되지만 입력이 비어 있으면 작성 페이지로 리디렉션됩니다. 원하는 것은 whict이지만 문제점은 다음과 같은 오류 메시지를 보내지 않을 것입니다. 리다이렉트는 유효성 검사기를 DD 해 주었고 모든 메시지가 잘 보였다. 내 의견은

<form class="form-horizontal" role="form" method="POST" action="{{ Route('userstore') }}"> 
        {!! csrf_field() !!} 

        <div class="form-group{{ $errors->has('name') ? ' has-error' : '' }}"> 
         <label class="col-md-4 control-label">الاسم</label> 

         <div class="col-md-6"> 
          <input type="text" class="form-control" name="name" value="{{ old('name') }}"> 

          @if ($errors->has('name')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('name') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group {{$errors->has('UserName') ? 'has-error' : ''}}"> 
         <label class="col-md-4 control-label">اسم المستخدم</label> 

         <div class="col-md-6"> 
          <input type="text" class="form-control" name="UserName" value="{{ old('UserName') }}"> 
          @if ($errors->has('UserName')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('UserName') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group {{$errors->has('Phone') ? 'has-error' : ''}}"> 
         <label class="col-md-4 control-label">رقم الجوال</label> 

         <div class="col-md-6"> 
          <input type="text" class="form-control" name="Phone" value="{{old('Phone')}}"> 
          @if ($errors->has('Phone')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('Phone') }}</strong> 
           </span> 
          @endif 

         </div> 
        </div> 

        <div class="form-group {{$errors->has('SSN') ? 'has-error' : ''}}"> 
         <label class="col-md-4 control-label">الرقم الوطني</label> 

         <div class="col-md-6"> 
          <input type="text" class="form-control" name="SSN" value="{{old('SSN')}}"> 
          @if ($errors->has('SSN')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('SSN') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group {{$errors->has('SDT') ? 'has-error' : ''}}"> 
         <label class="col-md-4 control-label">نوع الوثيقة</label> 

         <div class="col-md-6"> 
          <input type="text" class="form-control" name="SDT" value="{{old('SDT')}}"> 
          @if ($errors->has('SDT')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('SDT') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group {{$errors->has('Country') ? 'has-error' : ''}}"> 
         <label class="col-md-4 control-label">الدولة</label> 

         <div class="col-md-6"> 
          <select class="form-control" name="Country"> 

           <option>الاردن</option> 
          </select> 

         </div> 
        </div> 

        <div class="form-group"> 
         <label class="col-md-4 control-label">المدينة</label> 

         <div class="col-md-6"> 
          <select class="form-control" name="City" > 
           <option>عمان</option> 
          </select> 

         </div> 
        </div> 

        <div class="form-group {{$errors->has('Location') ? 'has-error' : ''}}"> 
         <label class="col-md-4 control-label">اسم الشارع</label> 

         <div class="col-md-6"> 
          <input type="text" class="form-control" name="Location" value="{{old('Location')}}"> 
          @if ($errors->has('Location')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('Location') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group{{ $errors->has('email') ? ' has-error' : '' }} ltr-input"> 
         <label class="col-md-4 control-label">البريد الإلكتروني</label> 

         <div class="col-md-6"> 
          <input type="email" class="form-control" name="email" value="{{ old('email') }}"> 

          @if ($errors->has('email')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('email') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group{{ $errors->has('password') ? ' has-error' : '' }} ltr-input"> 
         <label class="col-md-4 control-label">كلمة المرور</label> 

         <div class="col-md-6"> 
          <input type="password" class="form-control" name="password"> 

          @if ($errors->has('password')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('password') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group{{ $errors->has('password_confirmation') ? ' has-error' : '' }} ltr-input"> 
         <label class="col-md-4 control-label">تأكيد كلمة المرور</label> 

         <div class="col-md-6"> 
          <input type="password" class="form-control" name="password_confirmation"> 

          @if ($errors->has('password_confirmation')) 
           <span class="help-block"> 
            <strong>{{ $errors->first('password_confirmation') }}</strong> 
           </span> 
          @endif 
         </div> 
        </div> 

        <div class="form-group"> 
         <div class="col-md-6 col-md-offset-4"> 
          <button type="submit" class="btn btn-primary pull-right"> 
           <i class="fa fa-btn fa-user"></i> تسجيل 
          </button> 
         </div> 
        </div> 
       </form> 
(210)

및 BTW이 5.1

+0

에 laravel 5.1에서 내 프로젝트를 업그레이드하여 문제를 해결 laravel입니다 lost – Snapey

+0

@Snapey 당신은 무엇을 의미합니까? –

+0

플래시 된 데이터 (및 이전 데이터)가 한 요청에 대해서만 존재 함을 의미합니다. 다시 리디렉션 한 다음 다시 리디렉션하면 이전 양식 데이터가 손실됩니다 – Snapey

답변

0

내가 관리자/사용자/create`는 달리 플래시 메시지가 될 것입니다 리디렉션을 수행하지 않는`있는지 확인하십시오 5.5