dimanche 24 février 2019

Laravel laravel-users add fields to CRUD forms

I'm using the laravel-users package to add user management functionality to my Laravel 5.7 application but I'm struggling to figure out how to add additional fields to the user create / user edit forms so that they match my user table schema.

Users table definition:

    Schema::create('users', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('email')->unique();
        $table->timestamp('email_verified_at')->nullable();
        $table->string('password');
        $table->string('phone_number', 13);
        $table->boolean('is_super_admin')->default(false);
        $table->rememberToken();
        $table->timestamps();
    });

Specifically I want to add the phone_number field to the forms. I've updated the blade template adding in the markup for the field:

                <div class="form-group has-feedback row ">
                    @if(config('laravelusers.fontAwesomeEnabled'))
                        {!! Form::label('phone_number', __('auth.phone_number'), array('class' => 'col-md-3 control-label')); !!}
                    @endif
                    <div class="col-md-9">
                        <div class="input-group">
                            {!! Form::text('phone_number', NULL, array('id' => 'phone_number', 'class' => 'form-control', 'placeholder' => __('auth.phone_number'))) !!}
                            <div class="input-group-append">
                                <label class="input-group-text" for="phone_number">
                                    @if(config('laravelusers.fontAwesomeEnabled'))
                                        <i class="fa fa-fw {!! __('laravelusers::forms.create_user_icon_username') !!}" aria-hidden="true"></i>
                                    @else
                                        {!! __('auth.phone_number') !!}
                                    @endif
                                </label>
                            </div>
                        </div>
                        @if ($errors->has('phone_number'))
                            <span class="help-block">
                                    <strong></strong>
                                </span>
                        @endif
                    </div>
                </div>

But it seems that the actual creation of the user is handled by the UsersManagementController that's part of the package itself. How can I override this so that I can have it store the new field I've added?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire