Laravel 5从默认身份验证创建自定义注册和登录

编程入门 行业动态 更新时间:2024-10-24 04:34:44
本文介绍了Laravel 5从默认身份验证创建自定义注册和登录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

经过2年cakePhp的经验,最近我开始学习laravel框架.我已经为我的新项目创建了数据库,并使用

After 2 years experience in cakePhp , recently i started learning laravel framework. i already created the database for my new project and create a default authentication system with laravel 5 using the

php artisan make:auth 但我无法根据我的数据库设计对其进行修改 我有一个

php artisan make:auth but i cant modify it according to my database design i have a

  • 用户表(id,用户名,密码,remember_token)
  • 用户个人资料表(id,名字,姓氏等)
  • 组表(id,group_name)
  • group_users(group_id,users_id)
  • users_user_profiles(用户ID,user_profile_id)

因此,我想使用上表来实现基于组的用户管理系统.

so using the above table i want to implement a group based user management system.

如果我使用默认的身份验证系统,

if i use the default authentication system ,

  • 如何通过一次注册将登录和注册详细信息存储到两个表中?以及如何将ID自动插入数据透视表users_user_profiles表中?
  • 如何为注册创建一个包含登录详细信息和注册详细信息的视图,如何将它们分开以及如何分别访问请求数据以存储到两个单独的表中?
  • 如果有人可以提供详细的说明,它将对所有laravel 5初学者有所帮助,我认为这对所有新手来说都是一个共同的问题. 请帮我 谢谢

    if anybody can provide a detailed description on this, it will help all laravel 5 beginners, i think its a common problem for all newbies.. please help me Thanks

    推荐答案

    首先定义好您的模型,以便您能雄辩地使用,例如与user_profiles建立连接:

    First define good your models, so you can use eloquent, for example making connection with user_profiles:

    public function profiles() { return $this->belongsToMany('UserProfile'); }

    (只有当您获得UserProfile模型时才有可能) 然后,通过添加first_name,last_name等扩展注册表单.在创建用户

    (It will be possible only when you get UserProfile model) Then you extend your register form by adding first_name, last_name, etc. In auth controller after creating user

    $user = User::create([ 'name' => $data['name'], 'email' => $data['email'], 'password' => bcrypt($data['password']), ]);

    添加创建用户个人资料的代码:

    Add code that create user profile:

    $userProfile = UserProfile::create([ 'first_name' => $data['name'], 'last_name' => $data['email'] ]);

    然后通过附加命令(如果您有很多命令,则可以使用同步):

    Then add it to user by attach command (if you have many of them you can use sync) :

    $user->userProfiles()->attach($userProfile->id);

    有关用户身份验证工作原理的更多信息,您可以找到消除文件:\vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php

    More info about how user Authentication work you can find exterminating file: \vendor\laravel\framework\src\Illuminate\Foundation\Auth\RegistersUsers.php

    更多推荐

    Laravel 5从默认身份验证创建自定义注册和登录

    本文发布于:2023-11-04 00:53:37,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/1556515.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:自定义   身份验证   Laravel

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!