To return only unique results in a many-to-many relationship, you can use the distinct() method in Laravel. Here's how you can modify your code to achieve this:
public function allCharges(): BelongsToMany
{
return $this->belongsToMany(
AccountAdvertisementCharges::class,
'account_payment_charges',
'payment',
'charge'
)->distinct();
}
By adding the distinct() method to your relationship, it will ensure that only unique results are returned.
Remember to update your code accordingly and test it to ensure it works as expected.