79712515

Date: 2025-07-23 20:21:19
Score: 0.5
Natty:
Report link

You can do this using laravel eloquant. First create these modals

Country, PaymentMethod, CountryPaymentMethod, PaymentMethodConfiguration

And then create these relationships inside modals.

// Country.php
public function countryPaymentMethods()
{
    return $this->hasMany(CountryPaymentMethod::class);
}

// PaymentMethod.php
public function countryPaymentMethods()
{
    return $this->hasMany(CountryPaymentMethod::class);
}

// CountryPaymentMethod.php
public function configurations()
{
    return $this->hasMany(PaymentMethodConfiguration::class);
}

public function country()
{
    return $this->belongsTo(Country::class);
}

public function paymentMethod()
{
    return $this->belongsTo(PaymentMethod::class);
}

// PaymentMethodConfiguration.php
public function countryPaymentMethod()
{
    return $this->belongsTo(CountryPaymentMethod::class);
}

And you can query them like this

$country = Country::where('name', 'Ireland')->first();
$paymentMethod = PaymentMethod::where('name', 'Mobile Money')->first();

$configurations = PaymentMethodConfiguration::whereHas('countryPaymentMethod', function ($query) use ($country, $paymentMethod) {
    $query->where('country_id', $country->id)
          ->where('payment_method_id', $paymentMethod->id)
          ->where('is_active', true);
})->get();

Study about this more here

Laravel - Eloquent "Has", "With", "WhereHas" - What do they mean?

Reasons:
  • Probably link only (1):
  • Long answer (-1):
  • Has code block (-0.5):
  • Ends in question mark (2):
  • High reputation (-1):
Posted by: vimuth