Awais Qarni Awais Qarni - 4 months ago 31
PHP Question

Using packages in Laravel 5.1

I am using laravel 5.1. I want to use XML parser and I have searched and found Orchestra as mostly being used. So I have gone thorough all the steps given at documentation to install and configure. I have added

Orchestra\Parser\XmlServiceProvider::class
in
providers
section of
config/app.php
and
'XmlParser' => Orchestra\Parser\Xml\Facade::class
in
aliases
section.

Now in my controller, I have added its name space like
use Orchestra\Parser\Xml\Facade;
at the top of my controller. But when i try to use its function in my action, like

$xml = XmlParser::load($xml_document);


It generates error stating,

Class 'App\Http\Controllers\XmlParser' not found


So I want to know is there any other way in
Laravel 5.1
to use the packages and I am doing some thing wrong with
Orchestra
if some one has used it.

Answer

Since the documentation already describe registration of the facade alias:

'XmlParser' => Orchestra\Parser\Xml\Facade::class,

You can either use \XmlParser::load(), or import the alias.

use XmlParser;

or import the full namespace.

use Orchestra\Parser\Xml\Facade as XmlParser;