|
123456789101112131415161718192021222324252627282930313233343536373839404142 |
- <?php
-
- namespace App\Http\Controllers;
-
- use Illuminate\Http\Request;
- use App\Models\XmlData;
-
- class SaveXmlController extends Controller
- {
- public function index(Request $req)
- {
- if($req->isMethod("POST")){
-
- $xmlDataString = file_get_contents(public_path('places.xml'));
- $xmlObject = simplexml_load_string($xmlDataString);
-
- $json = json_encode($xmlObject);
- $phpDataArray = json_decode($json, true);
-
-
-
- if(count($phpDataArray['place']) > 0){
-
- $dataArray = array();
-
- foreach($phpDataArray['place'] as $index => $data){
-
- $dataArray[] = [
- "place place_id" => $data['place_id'],
- "name" => $data['name'],
- ];
- }
-
- XmlData::insert($dataArray);
-
- return back()->with('success','Data saved successfully!');
- }
- }
-
- return view("xml-data");
- }
- }
|