Laravel laravel-users为CRUD表单添加字段

问题描述 投票:0回答:1

我正在使用laravel-users软件包向我的Laravel 5.7应用程序添加用户管理功能,但我很难弄清楚如何向用户创建/用户编辑表单添加其他字段,以便它们与我的用户表模式匹配。

用户表定义:

    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();
    });

具体来说,我想将phone_number字段添加到表单中。我已经更新了在该字段的标记中添加的刀片模板:

                <div class="form-group has-feedback row {{ $errors->has('phone_number') ? ' has-error ' : '' }}">
                    @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>{{ $errors->first('phone_number') }}</strong>
                                </span>
                        @endif
                    </div>
                </div>

但似乎用户的实际创建是由UsersManagementController处理的,这是包本身的一部分。我怎样才能覆盖它,以便我可以存储我添加的新字段?

php laravel laravel-5 user-management
1个回答
0
投票

没有详细阅读完整的解释(因为我目前在本网站上几乎没有声明只是发表一些评论来澄清问题,而不是尝试答案......)这里有一些建议;)

您可能需要进入UsersManagementController并编辑更新功能以允许保存新添加的字段“phone_number”。

您的控制器很可能位于:

应用程序/ HTTP /控制器/ UsersManagementController.php

您需要编辑的功能看起来像这样

public function update(Request $request, $id) {

// Find the User that needs to be updated
$user = Post::find($id);
$user->phone_number = $request->input('phone_number');
//... some more code here
$user->save();

return //whatever is returned here... potentially redirected
}

要找到所有路由列表,如果这是问题并连续调整您的表单帖子以将数据提交给正确的控制器(这将列出您当前管理的所有路由): php artisan route:list

如果没有控制器,你应该创建一个,并确保将其添加到:

路线/ web.php

希望这可以帮助

© www.soinside.com 2019 - 2024. All rights reserved.