save the role_id into your users table?
You would use attach if a user can have many roles, and have a role_user pivot table
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
Hi, I wanted some help, I wanted to assign a fixed role id '2' to new user.
my controller code for create method is
public function create() { abort_if(Gate::denies('user_access'), Response::HTTP_FORBIDDEN, '403 Forbidden');
$roles = Role::pluck('title', 'id');
return view('users.create', compact('roles'));
}
the above method lets select role in user view. I want to simply attach the id in controller.
I tried using attach & find functions without success. Any help will be highly appreciated.
Please or to participate in this conversation.