Skip to content

Custom Object in pipeline #73

@kapdom

Description

@kapdom

How to pass custom object from one method to another.

For example in first method (parse) I grab collection of items and in for each loop I added new entry to DB and create eloquent object. Next I would like to for each element call another request and parse in another method but I need to pass Object to that parse method as well.
How can I do it?

public function parse(Response $response): Generator
    {
        $linksObject = $response
            ->filter('a.make');

        foreach ($linksObject as $obj) {
            $carBrand = Brand::firstOrCreate(['name' => trim($obj->textContent)]);
            $url = $obj->getAttribute('href');
           
            $this->request(
                'GET',
                 self::BASE_URI.$url,
                'getModels',
            
            );
        }
    }
public function getModels(Response $response, Brand $brand): \Generator
    {
        $models = $response->filter('.model-selector-box');
        foreach ($models as $model) {
            $url = $model->getAttribute('href');
            $model = trim($model->getElementsByTagName('h2')[0]->nodeValue);
            $realUrl = self::BASE_URI.$url;
            yield $this->request(
                'GET',
                $realUrl,
                'getGeneration'
            );
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions