<?php

namespace App\Classes\General\Eloquent\Filters;


use Illuminate\Database\Eloquent\Builder;
use Illuminate\Support\Facades\Auth;

class HasUsedVoucher implements Filter
{

    /**
     * @param Builder $builder
     * @param $value
     * @return mixed
     */
    public static function apply(Builder $builder, $value)
    {
        return $builder->where('user_id', Auth::user()->id)
        ->where(function ($query) {
            $query->whereHas('voucher', function ($subquery) {
                $subquery->whereHas('redemptions', function ($subsubquery) {
                    $subsubquery->whereHas('transaction', function ($subsubsubquery) {
                        $subsubsubquery->whereHas('owner');
                     });
                });
            });
        });
    }
}
