Extend EntryModel stub
Created 1 year ago by girvydas

I am building activitylog-extension and I want to extend generated Stream model with Trait, but i cant do that because bindings: 'Anomaly\Streams\Platform\Entry\EntryModel' => 'Demo\DemoExtension\Entry\EntryModel', are not working. I found that Anomaly\Streams\Platform\Entry\Command\GenerateEntryModel class is generating for example 'ContactsContactsEntryModel' class from 'resources/stubs/models/entry.stub' and in that file i can not add more traits or extend other class. How can I override that funcionality?

ryanthompson  —  1 year ago

Is it something you can use a hook for? Maybe explain how you're planning on doing this and I can help confirm but a hook should do it.

girvydas  —  1 year ago

I want to integrate https://github.com/spatie/laravel-activitylog this package. So I created new extension "activitylog-extension", generated new migration for building table and in my extension registered provider. Next I am trying to do model events logging (https://docs.spatie.be/laravel-activitylog/v1/advanced-usage/logging-model-events) and for example I have Contacts module with Demo\ContactsModule\Contact\ContactModel and in this model I want to add trait (use LogsActivity;), but I don't want to add it manually, Maybe that trait can be added in auto-generated model "ContactsContactsEntryModel". Reason why I don't want to add it manually is that I want my new "activitylog-extension" act like a package and automatically add LogsActivity trait.

ryanthompson  —  1 year ago

You could extend the entry compiler - I have seen that done before - but also.. You can use hooks to do this. And probably add an observer to the entry model that checks if logs activity then run the logging logic via hooks.

In the meanwhile - I'm not sure what the best way to hook into the compilers would be other than extending / binding it (the one you need specifically).