This forum has moved to a new location and is in read-only mode. Please visit talk.octobercms.com to access the new location.

PolloZen
PolloZen

How can I share functions between components, for example, I have the next function

public function findAccount()
{
    $account = Account::where('email',$this->variable['email'])->first();
    return $account;
}

This function is used in 3 diferent components but I don't want to have it in the three components

plugins/author/plugin/components/user.php

plugins/author/plugin/components/account.php

plugins/author/plugin/components/billing.php

Any ideas? Wich is the bettter aproach?

mjauvin
mjauvin

There's at least 3 ways to do this:

  • put those functions in a class and use the class in your components
  • just a bare php include of a file defining those functions
  • create a trait and use the trait in your components class
PolloZen
PolloZen

Thank You so much @mjauvin

I'm going to build my own class in /author/plugin/classes/userclass.php

Nice day

1-3 of 3

You cannot edit posts or make replies: the forum has moved to talk.octobercms.com.