Laravel 5 creating custom registration and login from default Authentication

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
but i cant modify it according to my database design
i have a

  • users table(id,username,password,remember_token)
  • user_profiles table (id,first_name,last_name etc)
  • group table(id,group_name)
  • group_users(group_id,users_id)
  • users_user_profiles (user_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. how can i store login and registration details into two tables with a single registration from? and how can i insert the id’s into pivot table users_user_profiles table automatically ?
  2. How to create a view for the registration which contain both the login details and registration details, how can i separate them and how to access the request data separately for storing into two separate tables?

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

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

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

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

(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);

More info about how user Authentication work you can find exterminating file: vendorlaravelframeworksrcIlluminateFoundationAuthRegistersUsers.php


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x