Skip to main content

Black Friday 2025! Only until December 1st: coupon FRIDAY25 for 40% off Yearly/Lifetime membership!

Read more here

monicahq/monica

23656 stars
1 code files
View monicahq/monica on GitHub

app/Models/Contact/Tag.php

Open in GitHub
use Illuminate\Support\Facades\DB;
use Illuminate\Database\Eloquent\Model;
 
class Tag extends Model
{
//
public static function contactsCount()
{
return DB::table('contact_tag')->selectRaw('COUNT(tag_id) AS contact_count, name, tag_id AS id')
->join('tags', function ($join) {
$join->on('tags.id', '=', 'contact_tag.tag_id')
->on('tags.account_id', '=', 'contact_tag.account_id');
})
->join('contacts', function ($join) {
$join->on('contacts.id', '=', 'contact_tag.contact_id')
->on('contacts.account_id', '=', 'contact_tag.account_id');
})
->where([
'tags.account_id' => auth()->user()->account_id,
'contacts.address_book_id' => null,
])
->groupBy('tag_id')
->get()
->sortByCollator('name');
}
}

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.