mrmrn mrmrn - 10 days ago 6
PHP Question

Class 'App\Http\Controllers\Illuminate\Container\Container' not found

I want to parse an XML.
I writed this ResultController

<?php
namespace App\Http\Controllers;

use Auth;
use \App\User;
use Illuminate\Http\Request;
use XmlParser;
use Illuminate\Container\Container;
use Orchestra\Parser\Xml\Document;
use Orchestra\Parser\Xml\Reader;

class ResultController extends Controller
{

public function getResults()
{

$xml = XmlParser::load('http://www.xmlsoccer.com/FootballDataDemo.asmx/GetAllTeams?ApiKey=ZXRIQOWMCFARAWRQIMSLRXCTSZDOBNLOTYWXYXMZYGDSENFSRB');
$app = new Illuminate\Container\Container;
$document = new Orchestra\Parser\Xml\Document($app);
$reader = new Orchestra\Parser\Xml\Reader($document);

$xml = $reader->load('http://www.xmlsoccer.com/FootballDataDemo.asmx/GetAllTeams?ApiKey=ZXRIQOWMCFARAWRQIMSLRXCTSZDOBNLOTYWXYXMZYGDSENFSRB');
$user = $xml->parse([
'users' => ['uses' => 'Team[Team_Id,Name]'],
]);

// dd($xml);
return view ('results.live');
}


}


I used use Illuminate\Container\Container; at top of the controller but it gaves me this error:


FatalErrorException in ResultController.php line 13: Class
'Illuminate\Container\Container\Controller' not found.


I cant understand what is wrong with it?

Answer

If you've used use keyword above -

use Illuminate\Container\Container;
use Orchestra\Parser\Xml\Document as OrchestraDocument;
use Orchestra\Parser\Xml\Reader as OrchestraReader;

you should use it inside method as (updated):

$app = new Container;
$document = new OrchestraDocument($app);
$reader = new OrchestraReader($document);

As you've used new Illuminate\Container\Container the php would find your container as - App\Http\Controllers\Illuminate\Container\Container, which isn't the correct path, the use keyword helps php to recognize the namespace of class Container

For more info see PHP Namespacing Docs

Hope this helps!