问题
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