slug)) { $tag->slug = Str::slug($tag->name); } }); } /** * Get the documents that have this tag */ public function documents() { return $this->belongsToMany(Document::class, 'document_document_tag') ->withTimestamps(); } /** * Get count of active documents with this tag */ public function activeDocuments() { return $this->belongsToMany(Document::class, 'document_document_tag') ->where('status', 'active') ->withTimestamps(); } }