Closed tnorthcutt closed 6 years ago
Update: I did end up extending the Tag
model to override findOrCreate()
and findOrCreateFromString()
and add a Team
parameter, which I'm passing along in my overridden trait method attachTags()
.
Hopefully this helps anyone else who comes across a similar situation.
And, if there's a better way of approaching this, I'd of course love to know 😄
@tnorthcutt Would you consider sharing your code? I have a similar requirement of separating tags by the company that added them.
@ptrin Sure! Here's a gist: https://gist.github.com/tnorthcutt/d76dbb7581b0f2a878d3f8042542e08e
That's not 100% of my implementation but I think it's the relevant parts. Happy to answer questions or add to that as necessary.
travis@memberup.co – I may not spot comments on the gist 😄
I'm using Laravel Spark, and this trait to scope various models by team.
I'm wondering if there's a Right Way™ to do the same thing for tags as provided by this package.
So far I've successfully added a migration to add a
team_id
column to thetags
table, and that works for e.g.I can also save an associated
team_id
when creating a tag, for instance with:This works great. However, that still leaves things like using
$model->attachTag('tagstring')
, since it uses$className::findOrCreate($tags)
, and thus doesn't have a chance to pass in ateam_id
.Is this a situation where I need to override the relevant trait methods to pass along a
team_id
, and then extend theTag
model to modify the relevant methods there (e.g.findOrCreate
)?That seems like the only logical way forward, but I wanted to ask before proceeding in case there's a simpler path I'm not seeing.
Thank you for this package, it's been quite easy to get up and running with it so far 😊