jovixv / dataforseo_client

PHP Client for DataForSeo API
MIT License
10 stars 7 forks source link

Undefined index: DFSClient #3

Closed mehulvadodariya2012 closed 5 years ago

mehulvadodariya2012 commented 5 years ago

Hi Team I am developing with laravel 5.6 PHP7.1

Error Screenshot image

Code Screenshot image

jovixv commented 5 years ago

You can add DFSClient to the laravel service provider as singlton. This may help. If it doesn't I will roll out the laravel version today.

mehulvadodariya2012 commented 5 years ago

Same error getting with laravel service provider

jovixv commented 5 years ago

It is working solution. You can use it. Full version for laravel will be provide today.

AppServiceProvider


namespace App\Providers;

use DFSClient\DFSClient;
use Illuminate\Support\ServiceProvider;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $GLOBALS['DFSClient'] = new DFSClient('your login', 'your password');
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {

    }
}

Controller


    public function demo ()
    {
        $model     = new RelatedKeywords();

        $completed  = $model->setOpt('keyword','big data')
            ->setOpt('language', 'en')
            ->setOpt('country_code', 'US')
            ->setOpt('depth', 2)
            ->get();

        if (!$completed->isSuccessFul())
            dd($completed);

        dd($completed);
            // you can call property as described below
        echo 'status: '       .$completed->status        ."<br>";
        echo 'results_time: ' .$completed->results_time  ."<br>";
        echo 'results_count: '.$completed->results_count ."<br>";

        foreach ($completed as $key=>$item) {
            dump($item);
        }
    }
jovixv commented 5 years ago

Also, when you use tasks. You must call getAfterMerge. example:



$model     = new SettingTasks();

$pool[] = $model::setOpt('site', 'ranksonic.com')->setOpt('crawl_max_pages', 10);
//$pool[] = $model::setOpt('site', 'ranksonic.com')->setOpt('crawl_max_pages', 10); -if it will be uncommented, script will send 2 tasks

$completed = SettingTasks::getAfterMerge($pool);

if (!$completed->isSuccessful())
    dd($completed);

foreach ($completed as $key=>$item){
    dump($item);
mehulvadodariya2012 commented 5 years ago

What is the use of getAfterMerge method?

jovixv commented 5 years ago

https://github.com/jovixv/dataforseo_client/wiki/Set-tasks--onpage

mehulvadodariya2012 commented 5 years ago

Thanks you

swash13 commented 4 years ago

Guys, sorry for re-open the issue, but how to install version for laravel ? composer require "jovixv/dataforseo_client:v1.0.1-laravel" is not working, but i see this version in "Releases". Also, is it possible to not use $GLOBALS for DFSClient ? Can i just construct it without a need to put it in AppService provider. It will make it more flexible. I want to configure it on a fly and there is no need to put it in AppServiceProvider. Example: $DFSClient = new DFSClient('Your Login','Your Password'); $model = new SettingSerpTasks();