<?php

namespace App\Classes\General\Eloquent\Filters;

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

class HasActiveReward implements Filter
{

    /**
     * @param Builder $builder
     * @param $value
     * @return Builder|mixed
     */
    public static function apply(Builder $builder, $value)
    {
        return $builder->where('user_id', Auth::user()->id) //cief todo: should not use Auth::user()->id
        ->where(function ($query) {
            $query->whereHas('reward', function ($subquery) {
                $subquery->where('is_active', true);
            });
            // ->orWhereDoesntHave('reward');
        });
    }

}
