<?php

namespace App\Classes\General\Eloquent\Filters;

use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;

class CreatedBeforeOrEqual implements Filter
{

    /**
     * @param Builder $builder
     * @param $value
     * @return mixed
     */
    public static function apply(Builder $builder, $value)
    {
        $table = $builder->getModel()->getTable();
        $endDate = Carbon::createFromFormat('d-m-Y', $value)->endOfDay();    
        return $builder->where("{$table}.created_at", '<=', $endDate);
    }
}
