You can just change a variable name $newUser to $user.
Apr 29, 2021
8
Level 12
help refactoring this code is easy,,,,
hi I git this code and want to know how I can make it shorter
$newUser = User::create([
'name' => $request->userName,
'email' => $request->email,
'password' => Hash::make($request->password),
]);
$newUser->profile()->create();
$newUser->wallet()->create();
$newUser->rank()->create();
$newUser->table1()->create();
$newUser->table2()->create();
$newUser->table3()->create();
...
...
... more tables to instantiate and create
I got a New User-created then got to create the relation tables and there are like 20 tables can this be encapsulated on a function or a callback? maybe under something like this
$newUser->create([
profile(),
wallet(),
rank(),
]);
thanks in Advance
Please or to participate in this conversation.