Hi,
I have 1 form which is submitting data for 3 different tables
1 form:
- saves info into User table
- saves info into Ico table
- saves info into Team table
Saving data into User and Ico table is working fine but now i try to save data into Team table
the problem is that the team section of the form is contains dynamically added input fields
so when i dd the requested $data in my RegisterController.php i have thees:
My question is how to save teamname , teamrole, and teamlinkedin into my team table
the are Array inside an Array and i dont know how to extract the data from them.
array:12 [▼
"_token" => "Ox7pnUbXTxoc9ppMM7mgHJQAyIUAkjEvUv8NaXCU"
"username" => "Username"
"email" => "[email protected]"
"password" => "userpassword"
"password_confirmation" => "userpassword"
"iconame" => "ICO project name"
"description" => "<p>This is the description of the ICO project .....</p>"
"teamname" => array:2 [▼
0 => "Team member name 1"
1 => "Team member name 2"
]
"teamrole" => array:2 [▼
0 => "Developer"
1 => "Developer 2"
]
"teamlinkedin" => array:2 [▼
0 => "www.linkedin.com/teammemeber1profile"
1 => "www.linkedin.com/teammember2profile"
]
"customLogo" => UploadedFile {#561 ▶}
"teamprofpic" => array:2 [▼
0 => UploadedFile {#563 ▶}
1 => UploadedFile {#564 ▶}
]
]
this is the way i try to save the info into my database:
protected function create( array $data)
{
dd($data);
$user = new User();
$user->name = $data['username'];
$user->email = $data['email'];
$user->password = Hash::make($data['password']);
$user->save();
$user->attachRole('icouser');
$request = request();
$logo = $request->file('customLogo');
$logoname = uniqid($user->id."_").".".$logo->getClientOriginalExtension();
Storage::disk('s3')->put($logoname, File::get($logo), 'public');
$url = Storage::disk('s3')->url($logoname);
$ico = new Ico();
$ico->iconame = $data['iconame'];
$ico->user_id = $user->id;
$ico->description = $data['description'];
$ico->logo = $url;
$ico->save();
----------->code above works perfectly,, code below does not....
foreach ($teamname as $teamnames) {
foreach ($teamrole as $teamroles) {
foreach ($teamlinkedin as $teamlinkedins) {
$team = new Team();
$team->user_id = $user->id;
$team->tmembername = $teamnames;
$team->tmembertile = $teamroles;
$team->tmemberlinkedin = $teamlinkedins;
}
}
$team->save();
}
return $user;
}