Support the ongoing development of Laravel.io →
posted 3 years ago
Architecture
Last updated 2 years ago.
0

Hi,

One question, any of the vendor which has for example the CSV method for pulling data, has the same structure for all the other CSV vendors?

I think we need some more details in order to supply a correct response, but i could give you an idea.

You can create an import method for you vendor model

Vendor::findOrFail($id)->import();

In the import logic, you can use the model data in order to know if the vendor needs a csv, or a rest api.. ecc ecc.

public function import()
{
    $data = [];

    // Check method for pulling data
    switch ($this->pull_method) {
        case 'CSV':
            $data = $this->pullCsv();
            break;
        case 'REST':
            $data = $this->pullHttp();
            break;
    }

    // Use the data as you want..
    return $data;
}

And you can write the single import method based on the required pulls, so you can call, import from any vendor, without worry about his pull method.

Hope it helps!

0

Hi Renato.

The combinations are unlimited. Some vendors send a CSV file, others send a json. Some vendors ask me to use their API and others simply upload an xslx file to a server via FTP. Even the ones who send it in CSV they do not share the same structure.

As you can see it is a mess. My plan is to create "connectors" or something like that.

0

Ok,

Maybe you can use the various $this->pullSource methods as connectors from your vendors, pulling all the data from the api. Next, you can write another method for the data management, maybe if you have stored the structure used by all the vendors, when you have the pulled data, you can extract only the needed data, knowing the vendor structure.

draidel liked this reply

1

Someone recommended me to consider the adapter pattern. What do you think?

0

Sign in to participate in this thread!

Eventy

Your banner here too?

Ariel draidel Joined 28 Apr 2020

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.