title: How to autofill fields in laravel?
body: <p>I am trying to make the <code>password</code> of the user the same as the <code>user id</code>. What i don't want is to copy and paste the <code>user id</code> from the <code>user id</code> field into the <code>password</code> field. Instead, what i want to achieve is that as soon as i enter the <code>user id</code>, the same values get input into the <code>password</code> field. how can i achieve this? Below is my code:</p>
  
  <p><strong>Blade :</strong></p>
  
  <pre><code>@extends('layouts.app')
  
  @section('content')
      &lt;div class="container"&gt;
          &lt;div class="row justify-content-center"&gt;
              &lt;div class="col-md-7"&gt;
                      &lt;div class="card"&gt;
                          &lt;div class="card-header"&gt;Add New User&lt;/div&gt;
                          &lt;div class="card-body"&gt;
                              {!! Form::open(['action'=&gt;'AccountsController@store', 'method'=&gt;'POST']) !!}
                              &lt;div class="row form-group justify-content-center"&gt;
                                  {{Form::label('name','Name',['class'=&gt;'col-md-2'])}}
                                  &lt;div class="col-md-4"&gt;
                                      {{Form::text('name','',['class'=&gt;'form-control', 'placeholder'=&gt;'Name'])}}
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="row form-group justify-content-center"&gt;
                                  {{Form::label('email','Email',['class'=&gt;'col-md-2'])}}
                                  &lt;div class="col-md-4"&gt;
                                      {{Form::text('email','',['class'=&gt;'form-control', 'placeholder'=&gt;'Email'])}}
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="row form-group justify-content-center"&gt;
                                  {{Form::label('userid','User I.D',['class'=&gt;'col-md-2'])}}
                                  &lt;div class="col-md-4"&gt;
                                      {{Form::text('userid','',['class'=&gt;'form-control', 'placeholder'=&gt;'User I.D'])}}
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="row form-group justify-content-center"&gt;
                                  {{Form::label('password','Password',['class'=&gt;'col-md-2'])}}
                                  &lt;div class="col-md-4"&gt;
                                      {{Form::password('password',['class'=&gt;'form-control', 'placeholder'=&gt;'Password'])}}
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="row form-group justify-content-center"&gt;
                                  {{Form::label('cpassword','Confirm Password',['class'=&gt;'col-md-2'])}}
                                  &lt;div class="col-md-4"&gt;
                                      {{Form::password('cpassword',['class'=&gt;'form-control', 'placeholder'=&gt;'Confrim Password'])}}
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="row form-group justify-content-center"&gt;
                                  {{Form::submit('Submit',['class'=&gt;'btn btn-primary'])}}
                              &lt;/div&gt;
                          {!! Form::close() !!}
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  @endsection
  </code></pre>
  
  <p><strong>controller :</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use Illuminate\Support\Facades\Hash;
  use App\Account;
  use App\User;
  
  class AccountsController extends Controller
  {
      /**
       * Display a listing of the resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function index()
      {
          // $accounts = Account::all();
          $accounts = User::all();
          return view('accounts.create');
      }
  
      /**
       * Show the form for creating a new resource.
       *
       * @return \Illuminate\Http\Response
       */
      public function create()
      {
          return view('accounts.create');
      }
  
      /**
       * Store a newly created resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @return \Illuminate\Http\Response
       */
      public function store(Request $request)
      {
          $this-&gt;validate($request,[
              'name'=&gt;'required',
              'email'=&gt;'required',
              'userid'=&gt;'required',
              'password'=&gt;'required'
          ]);
  
          // $account = new Account;
          $account = new User;
          $account-&gt;name = $request-&gt;input('name');
          $account-&gt;email = $request-&gt;input('email');
          $account-&gt;userid= $request-&gt;input('userid');
          $account-&gt;password = bcrypt($request-&gt;input('password'));
          $account-&gt;save();
  
          return redirect('/accounts')-&gt;with('success', 'User has been successfully added!');
      }
  
      /**
       * Display the specified resource.
       *
       * @param  int  $id
       * @return \Illuminate\Http\Response
       */
      public function show($id)
      {
          //
      }
  
      /**
       * Show the form for editing the specified resource.
       *
       * @param  int  $id
       * @return \Illuminate\Http\Response
       */
      public function edit($id)
      {
          //
      }
  
      /**
       * Update the specified resource in storage.
       *
       * @param  \Illuminate\Http\Request  $request
       * @param  int  $id
       * @return \Illuminate\Http\Response
       */
      public function update(Request $request, $id)
      {
          //
      }
  
      /**
       * Remove the specified resource from storage.
       *
       * @param  int  $id
       * @return \Illuminate\Http\Response
       */
      public function destroy($id)
      {
          //
      }
  }
  </code></pre>
  
  <p><strong>model :</strong></p>
  
  <pre><code>&lt;?php
  
  namespace App;
  
  use Illuminate\Contracts\Auth\MustVerifyEmail;
  use Illuminate\Foundation\Auth\User as Authenticatable;
  use Illuminate\Notifications\Notifiable;
  
  class User extends Authenticatable
  {
      use Notifiable;
  
      /**
       * The attributes that are mass assignable.
       *
       * @var array
       */
      protected $fillable = [
          'name', 'email','userid', 'password',
      ];
  
      /**
       * The attributes that should be hidden for arrays.
       *
       * @var array
       */
      protected $hidden = [
          'password', 'remember_token',
      ];
  
      /**
       * The attributes that should be cast to native types.
       *
       * @var array
       */
      protected $casts = [
          'email_verified_at' =&gt; 'datetime',
      ];
  }
  </code></pre>
  
  <p><strong>database :</strong></p>
  
  <pre><code>&lt;?php
  
  use Illuminate\Database\Migrations\Migration;
  use Illuminate\Database\Schema\Blueprint;
  use Illuminate\Support\Facades\Schema;
  
  class CreateUsersTable extends Migration
  {
      /**
       * Run the migrations.
       *
       * @return void
       */
      public function up()
      {
          Schema::create('users', function (Blueprint $table) {
              $table-&gt;bigIncrements('id');
              $table-&gt;string('name');
              $table-&gt;string('email')-&gt;unique();
              $table-&gt;timestamp('email_verified_at')-&gt;nullable();
              $table-&gt;string('userid')-&gt;unique();
              $table-&gt;string('password');
              $table-&gt;rememberToken();
              $table-&gt;timestamps();
          });
      }
  
      /**
       * Reverse the migrations.
       *
       * @return void
       */
      public function down()
      {
          Schema::dropIfExists('users');
      }
  }
  </code></pre>