Laravel 5从默认身份验证创建自定义注册和登录 [英] Laravel 5 creating custom registration and login from default Authentication

查看:173
本文介绍了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 ,

  1. 如何通过一次注册将登录和注册详细信息存储到两个表中?以及如何将ID自动插入数据透视表users_user_profiles表中?
  2. 如何为注册创建一个包含登录详细信息和注册详细信息的视图,如何将它们分开以及如何分别访问请求数据以存储到两个单独的表中?

如果有人可以提供详细的说明,它将对所有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从默认身份验证创建自定义注册和登录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆