Laravel default registration page I want to add an option to select a region, how to transfer the variables of the region list to the blade template?

1. The item adds a region list option to the register.blade template so that the user can choose the region when registering.
2. Excuse me in which file the register.blade template is called, but I can"t find it.
3. It wasn"t long before I started using laravel. I searched Baidu for a long time and didn"t find the answer I wanted.

<div class="form-group row">
                            <label for="areaid" class="col-sm-3 col-form-label text-md-right">/</label>
                            <div class="col-md-3">
                                <select class="form-control" id="areaid" name="areaid">
                                    <option value=""></option>
                                    @foreach ($data["areas"] as $k=>$v)
                                    <option value="{{ $v->id}}">{{ $v->name }}</option>
                                    @endforeach
                                 </select>
                             </div>
                        </div>

the error code is: "Undefined variable: data (View: E:xampphtdocsdibaoresourcesviewsauthregister.blade.php)"

Mar.18,2021

it seems that you use laravle default user authentication, and when you execute php artisan make:auth , it will generate layout, registration and login views and routes for all authentication interfaces. register.blade.php in resources.views.auth .

or you can execute php artisan route:list to find | GET | HEAD | register | register | App\ Http\ Controllers\ Auth\ RegisterController@showRegistrationForm , follow the controller. Notice that RegisterController uses trait . If you don't know trait , you can't find showRegistrationForm .


this is very simple. Modify the controller RegisterController directly and add the following function:

public function showRegistrationForm() {
    $data = [1, 2, 3, 4];
    return view ('auth.register')->with(['data' => $data]);
}

then call $data directly in your register.blade. Then remember to modify the validator and create functions inside the same file to detect and accept the new options. For example:

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

    /**
     * Create a new user instance after a valid registration.
     *
     * @param  array  $data
     * @return User
     */
    protected function create(array $data)
    {
        return User::create([
            'name' => $data['name'],
            'email' => $data['email'],
            'password' => bcrypt($data['password']),
            'areaid' =>$data['areaid'],
        ]);
    }
MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e48a4b-44ccd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e48a4b-44ccd.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?