feat(usermanagement): enhance user-branch relationship by syncing branches and adding timestamps
This commit is contained in:
@@ -217,11 +217,23 @@ class UsersController extends Controller
|
||||
|
||||
if ($validated) {
|
||||
$user = User::create($validated);
|
||||
|
||||
if ($user) {
|
||||
if ($request->roles) {
|
||||
$user->assignRole($request->roles);
|
||||
}
|
||||
|
||||
$branches = $request->input('branches', []);
|
||||
|
||||
$user->branches()->sync($branches);
|
||||
|
||||
if (!empty($branches)) {
|
||||
$firstBranchId = $branches[0];
|
||||
|
||||
$user->branch_id = $firstBranchId;
|
||||
$user->save();
|
||||
}
|
||||
|
||||
return redirect()->route('users.index')->with('success', 'User created successfully.');
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user