<?php

namespace App\Classes\General\Eloquent\Filters;

use App\Models\Company;
use Illuminate\Database\Eloquent\Builder;

class HasSegments implements Filter
{

    /**
     * @param Builder $builder
     * @param $value
     * @return mixed
     */
    public static function apply(Builder $builder, $value)
    {
        return $builder->whereHas('segments', function ($q) use ($value) {
            $q->whereIn('id', Auth()->user()->company()->first()->segments()->pluck('segment_id'));
        });
    }
}
