Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

BlastedAsh's avatar

Adding functions to a Model found in the vendor directory

Currently my situation is that I pulled in a Messenger dependency into my project.

It has a Thread model that is found here vendor/cmgmyr/messenger/src/Models/Thread.php.

Now I want to add some more relationships and functions into the Thread model. Without publishing that Thread model out of the vendor directory, what's the best way to add functions to it?

Ideally, I'd like to have a model titled Thread in my app directory that just inherits everything in the vendor Thread.php has but allows me to add my own code to it.

Does anyone have any suggestions?

0 likes
1 reply
BlastedAsh's avatar
BlastedAsh
OP
Best Answer
Level 4

Wow this was super simple actually. For anyone else with the same question - the solution is to extend the Vendor Model.

For my case, extending the Thread Model.

  1. Create model titled 'Thread' in App\Thread.php.
  2. Import the Vendor model:
use Cmgmyr\Messenger\Models\Thread as CmgmyrThreadModel;
  1. Have the Thread.php in your App\ directory extend it:
class Thread extends CmgmyrThreadModel
  1. Ensuring you vendor published your vendors config file. Set 'thread_model' => to equal the directory of the Thread.php in your App directory.

  2. You can now add extra functions / relationships to the App\Thread.php.

1 like

Please or to participate in this conversation.