I am loading data from an XML file and also trying to dynamically be able to match these values from the XML elements, in to my database table. I am using Laravel 5.6.
This is what I have now:
config.php:
'milestone' => [
'columns' => array(
"JobDept" => "department",
"JobBranch" => "branch",
"Destination" => "destination",
),
],
The above array have the following format, which maps my XML fle to my database columns:
"XML Element Name => Database Column Name"
So, I can now take the keys from above array (JobDept, JobBranch, Destination) and find these in my XML files:
$data = $xml->parse([
'report' => ['uses' => 'item['.implode(",",$xmlFilters).']', 'default' => null]
]);
Above works just fine. This will populate the keys with actual values from my XML file:
0 => array:3 [▼
"JobDept" => "FEA"
"JobBranch" => "AAL"
"Destination" => "TWTPE"
]
This is where I am stuck. Since my column names in my MySQL database is department, branch, destination I guess I need to change the array key names, to match my database column names, so the array will be like this:
0 => array:3 [▼
"department" => "FEA"
"branch" => "AAL"
"destination" => "TWTPE"
]
Any idea on how to achieve this dynamically? As said, I am using Laravel 5.6 as a framework.
Update:
This is my $data array:
"report" => array:1[▼
0 => array:3 [▼
"JobDept" => "FEA"
"JobBranch" => "AAL"
"Destination" => "TWTPE"
]
]
keywithmilestone[columns][key]