Class 'SEOstats\\SEOstats' not found when

2019-07-03 01:40发布

问题:

I am trying to use SEOstats php package in laravel, I've installed it using composer and then in my controller I have used it like below :

use SEOstats\Services as SEOstats;

class ReportageController extends Controller
{
 public function store(Request $request)
    {

        $url = 'http://www.google.com/';

        // Create a new SEOstats instance.
        $seostats = new \SEOstats\SEOstats;

        // Bind the URL to the current SEOstats instance.
        if ($seostats->setUrl($url)) {

            dd( SEOstats\Alexa::getGlobalRank());
        }
   }
}

The problem is I'm getting this error message :

Class 'SEOstats\SEOstats' not found

I've changed namespaces to different types but still getting this error. Any suggestion how to make it work in laravel 5.3

回答1:

$seostats = new SEOstats; will do the trick,

since you imported the class there is no need of the \ prefix



回答2:

Since you have given alias as SEOstats then you have to use alias

use SEOstats\Services as SEOstats;

class ReportageController extends Controller
{
 public function store(Request $request)
    {

        $url = 'http://www.google.com/';

        // Create a new SEOstats instance.
        $seostats = new SEOstats;

        // Bind the URL to the current SEOstats instance.
        if ($seostats->setUrl($url)) {

            dd( SEOstats::getGlobalRank());
        }
   }
}