Cool, I've been around that kind of architecture you're looking for. Check this laracast video after the minute 5 https://laracasts.com/series/simple-rules-for-simpler-code/episodes/2
You could combine the past comment that I said. And make a class for every type of connection.
So in the constructor for each class you just inject the model where the configs are saved and prepare the things you need to do.
So for example
class Magento implements EshopInterface {
public function __construct(Eshop $shop_model) {
$this->token_private = $shop_model->data->token_private;
//you can put the specific configurations for connection here or in another method
}
public function getLatestProducts(): array
{
//You put the action logic for retrieving the elements
//Always return the same type for this method that will be in each class
}
}
class Woocomerce implements EshopInterface {
public function __construct(Eshop $shop_model) {
$this->key = $shop_model->connection->key;
//you can put the specific configurations for connection here or in another method
}
public function getLatestProducts(): array
{
}
}
// It is not explicitly needed but will help you keep your app consistent to have an interface
interface EshopInterface
{
public function getLatestProducts(Request $request): array;
}
And after all is set, in your controller or wherever you instantiate the proper object
public function index()
{
// These ifs you could put it in a method in a class or the model itself here are for explanation
if(config('services.eshop') == 'magento'){
$eshop = new Magento($eshop_model);
} else if (config('services.eshop') == 'woocomerce'){
$eshop = new Woocommerce($eshop_model);
} else {
$eshop = new NullShop();
}
$eshop->getLatestProducts(); //Here you will not need to care about how to handle the connection
}
After all this I bet I didn't say anything more than the video LOL. But I hope it will also help non subscriptors.