Laravel Validation with return input values

Laravel Validation with return input values to following.

adduser.blade.php
   
<form class="connect-form form-horizontal" action="{{ route('user.submit') }}" method="post" enctype="multipart/form-data" >
                    {{ csrf_field() }}

<div class="col-sm-2">
                            <input type="text" name="fname" id="fname" class="form-control" placeholder=" Name" value="{{Request::old('fname')}}"/>
                            @if ($errors->has('fname'))
                                     <div class="invalid-feedback">
                                    {{ $errors->first('fname') }}
                                     </div>
                                     @endif
                        </div>
                        <div class="col-sm-2">
                                <input type="text" name="lname" id="lname" class="form-control" placeholder="Last Name" value="{{Request::old('lname')}}">
                                @if ($errors->has('lname'))
                                     <div class="invalid-feedback">
                                    {{ $errors->first('lname') }}
                                     </div>
                                     @endif
                     </div>
   </form>
UsersController.php

Add this function to controller


 public function create(Request $request)
    {
        $validator =  $this->validator($request->all());

     if($validator->fails()){
      return Redirect::back()->withErrors($validator)->withInput();
        }
   }
   protected function validator(array $data)
    {
        return Validator::make($data, [
            'fname' => 'required|max:255',
            'lname' => 'required|max:255',
        ]);
    }
web.xml

Route::post('/admin/adduser', 'UsersController@create')->name('user.submit');

No comments:

Post a Comment

how to call ssh from vs code

 To call SSH from VS Code, you can use the built-in Remote Development extension. This extension allows you to open a remote folder or works...