In this tutorial, we will learn How to Read XML File in Laravel


Add Simple Xml File:


you can create or download simple xml file 

Download XML Demo File


Controller Code:

<?php
  
namespace App\Http\Controllers;
   
use Illuminate\Http\Request;
  
class XMLController extends Controller
{
    /**
     * Write code on Method
     *
     * @return response()
     */
    public function index()
    {
        $xmlString = file_get_contents(public_path('sample.xml'));
        $xmlObject = simplexml_load_string($xmlString);
                   
        $json = json_encode($xmlObject);
        $phpArray = json_decode($json, true); 
   
        dd($phpArray);
    }
}


May this example help you.