<?php

namespace App\Classes\General\Eloquent\Filters;

use Illuminate\Database\Eloquent\Builder;

class HasPendingDelivery implements Filter
{

    /**
     * @param Builder $builder
     * @param $value
     * @return Builder|mixed
     */
    public static function apply(Builder $builder, $value)
    {
        return $value ? $builder->whereHas('packingLists', function (Builder $query) use($value) {
            $query->whereDoesntHave('transports');
        }) : $builder->whereDoesntHave('packingLists', function (Builder $query) use($value) {
            $query->whereDoesntHave('transports');
        });
    }

}