donglv9116 2016-04-11 22:51
浏览 146
已采纳

Laravel - 如何从单独的字段中获取名字和姓氏,并将它们存储在db中的名称列中?

So I used php artisan make:auth in my project and I am building on top of that. Problem is it has only "name" field and not "firstName" and "lastName" field. Where do I configure those options? I want to take the input from first name and last name and concatenate them with a space between them, then store them as name in my db. Where is the place to do that? Where do I configure my options like if I want to add an address or phone number for my user? I researched a lot and I am really confused with all those traits so please could someone give me some advice on how to proceed with user authentication?

  • 写回答

2条回答 默认 最新

  • du229908 2016-04-11 23:09
    关注

    For use name instead of first_name and last_name open database/migration/create_user_table write

    $table->string('name');

    instead of

    $table->string('first_name');
    $table->string('last_name');
    

    After that open app/Http/Controller/Auth/AuthController.php and then put your code like that

    protected function create(array $data)
        {
            return User::create([
                'name' => $data['first_name'].' '.$data['last_name'],
                'username' => $data['username'],
                'email' => $data['email'],
                'password' => bcrypt($data['password']),
            ]);
        }
    

    if you want to use more fields,write those fields in migration file which is on database/migration and then use those fields in resources/views/auth/register.blade.php that files's html form,and after that change AuthController.php file

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)
编辑
预览

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部