Thursday, March 2, 2017

How can i get data from database for dropdownlist in Register Form Laravel 5.4?

back again i have problem to show list data from database on my register form on laravel 5.4 (AdminLTE form). Anybody help me?

Coding register.blade.php:

<div class="form-group">
                  <label for="title">Pilih Kecamatan:</label>
                    <select name="kecamatan" id="kecamatan" class="form-control">
                        <option value="">--- Pilih Kecamatan ---</option>

                    </select>
                </div>
                <div class="form-group">
                    <label for="title">Pilih Desa:</label>
                    <select name="desa" id="desa" class="form-control"></select>
                </div>     

Coding RegisterController.php

use RegistersUsers;


public function showRegistrationForm()
{
    return view('adminlte::auth.register');
}


protected $redirectTo = '/home';


public function __construct()
{
    $this->middleware('guest');
}


protected function validator(array $data)
{
    return Validator::make($data, [
        'name'     => 'required|max:255',
        'username' => 'sometimes|required|max:255|unique:users',
        'email'    => 'required|email|max:255|unique:users',
        'password' => 'required|min:6|confirmed',
        'phone'    => 'required',
        'alamat'   => 'required',
        'kecamatan'=> 'required',
        'desa'     => 'required',
        'terms'    => 'required',
    ]);
}


protected function create(array $data)
{
    $fields = [
        'name'     => $data['name'],
        'email'    => $data['email'],
        'password' => bcrypt($data['password']),
        'phone'    => $data['phone'],
        'alamat'   => $data['alamat'],

    ];
    if (config('auth.providers.users.field','email') === 'username' && isset($data['username'])) {
        $fields['username'] = $data['username'];
    }
    return User::create($fields);
}

i need step how to get the data and how to show it on my register fields. thank you guys.




via Yosua Simanjuntak

Advertisement