Reputation: 103
I am creating a user registration system through the use of Laravel's auth service. I have 2 tables; 1 is the users table, and the other is the roles table (roles as in user roles (admin, standard). To link those 2 tables together, I have a pivot table called role_user, which uses the ids from the users table and the roles table. When a new user registers, I want the role_user table to create a row that contains the user's id from the users table, and the role's id from the roles table, so that the system knows that the user has the standard user role. The only code I have is the code that Laravel's auth service comes with. I do not know how to insert data into a pivot table.
Upvotes: 0
Views: 224
Reputation: 103
I was able to figure it out. Within the create function in the AuthController file, I applied the following:
$user = User::create([
...
]);
DB::table('role_user')->insertGetId(
...
);
return $user;
Then at that point, I could carry on the normal Laravel authentication service of returning the creation of the data that was submitted on the registration page.
Upvotes: 1