经过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 ,
如果有人可以提供详细的说明,它将对所有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从默认身份验证创建自定义注册和登录
发布评论