Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dragonfly's avatar

help with double tables and roles

OK so after asking a question about routes I was told to use roles. I have watched the acl video on roles but do not understand how to add a role and permission when a user registers. I also need help understanding how to make a registration form insert set data into a table while taking the name password etc that a users table requires and splitting the two. Hope that makes since in other words I want the user info for login on the users table but the registration info on another table along with giving it a roles connection so that it connects the two with the user name. So that a dashboard could pull through there info. I have a artist a viewer and a sponsor but I need each of those to have set roles and permissions when they register. For example once a artist has paid they can see there dashboard and edit there profile but they can not see or edit anyone else's profile. I know that's a roles thing I just do not understand how to give a user roles upon registration. I need roles given automaticly depending non user type.

I tried this code sample for splitting the data but it did not work. Let me rephrase it added to both tables but gave errors about user_id column when I fixed that gave me another error about session guard.

$user = new User($data); $user_details = new UserDetails($data); $user->save(); $user->user_detail()->save($user_details);

I got that from http://stackoverflow.com/questions/31121454/registering-a-user-in-laravel-5-and-send-data-to-two-tables-is-this-correct.

Any help or pointing me to a great tutorial would be much appreciate ed I learn better from seeing it done and explained then I can do it myself and adjust as I need.

Thanks again.

0 likes
4 replies
jlrdw's avatar

If you would look at the documentation for version 5.1 it has a better example of this. I think it will explain it better. Also the intermediate tutorial has a basic example of this.

dragonfly's avatar

I figured out the splitting tables I was making it a lot harder then it really was. Still not positive on roles and permissions but that's today's project.

jlrdw's avatar

Read up on authorization and using gate in the docs.

dragonfly's avatar

OK one more questions I figured out how to save the form to split tables it works great no problem. I have the first table set up to do an email verification. Is there a way to only add the user info to the users table after the verification is complete. This is to help prevent the user table from getting bogged down with people that don't complete the process of verifying there email. I have all the registration and email confirmation on my controlled method. Any suggestions on how to do this?

public function confirmEmail($token)
{
    Sponsor::whereToken($token)->firstOrFail()->confirmEmail();
    
    flash('You are now confirmed. Please login');
    
    
    if($this->userRegister($request)) {
        flash('thank you please sign in');
            return redirect()->intended('login');
    }
        flash('Could not create your account');
        return redirect()->back();
    }
    public function userRegister(Request $request)
{
    //Validate
    return ($this->validate($request, [
            'name' => 'required',
            'email' => 'required|email|unique:users',
            'password' => 'required'
        ]);
    //create sponsor
    $user = User::create($request->all());      
    //flash

}

Please or to participate in this conversation.