Class 'SEOstats\SEOstats' not found when calling SEOStats instances in laravel 5.3

南笙酒味 提交于 2019-12-23 20:00:31

问题


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());
        }
   }
}


来源:https://stackoverflow.com/questions/46523784/class-seostats-seostats-not-found-when-calling-seostats-instances-in-laravel-5

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!