donglv9116 2016-04-12 06: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-12 07: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条)

报告相同问题?

悬赏问题

  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥15 Oracle触发器记录修改前后的字段值
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 CSAPPattacklab
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图
  • ¥15 stm32开发clion时遇到的编译问题