2

I am having problems with a composer package I am dealing with. It implements a trait Billable.

trait Billable
{
/**
     * Update the payment method token for all of the user's subscriptions.
     *
     * @param  string  $token
     * @return void
     */
    protected function updateSubscriptionsToPaymentMethod($token)
    {
        foreach ($this->subscriptions as $subscription) {
            if ($subscription->active()) {
                BraintreeSubscription::update($subscription->braintree_id, [
                    'paymentMethodToken' => $token,
                ]);
            }
        }
    }
}

I am trying to override this method in my class

class Organisation extends Model
{

    use Billable;

    /**
     * Update the payment method token for all of the user's subscriptions.
     *
     * @param  string  $token
     * @return void
     */
    protected function updateSubscriptionsToPaymentMethod($token)
    {
        foreach ($this->subscriptions as $subscription) {
            if ($subscription->active()) {
                BrntreeSubscription::update($subscription->braintree_id, [
                    'paymentMethodToken' => $token,
                ]);
            }
        }
    }
}

But the method is not overridden. As a test I overrode some of the public functions and they work fine, it this a limitation of traits? I have tried to find the answer online but have come up short.

I am trying to override this function because I need to customize the behaviour of the BraintreeSubscription class.

Any help would be greatly appreciated.

Ben Ganley
  • 121
  • 1
  • 5
  • 3
    You can have a look at http://stackoverflow.com/questions/11939166/how-to-override-trait-function-and-call-it-from-the-overriden-function – olibiaz Sep 11 '16 at 23:34
  • you should also pass `subscriptions` as an argument. If you leave it as is it might throw error in somewhere you use `trait` and you have something other then `subscriptions` array. – Basheer Kharoti Sep 12 '16 at 04:36

1 Answers1

3

in your class you could do the following notice the T before the function name you may change this to be aliased as anything really.

use billable {
    updateSubscriptionsToPaymentMethod as tUpdateSubscriptionsToPaymentMethod;
}

then simply in the class add the desired function:

    public function updateSubscriptionsToPaymentMethod(){
      ...
   }
Sari Yono
  • 577
  • 5
  • 13