Showing posts with label validation. Show all posts
Showing posts with label validation. Show all posts

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');

Laravel how to validation in controller

In this tutorial learn how to validation in controller all variables in laravel. laravel validation working using the  validator function.

Defining The Routes
First, let's assume we have the following routes defined in our routes/web.php file:
Route::get('post/create', 'UserController@create');

Route::post('post', 'UserController@store');

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...