add eloquent filter.

This commit is contained in:
weichien
2021-06-05 15:56:56 +08:00
parent 9fb852d1ea
commit fe065f4f2f
2 changed files with 42 additions and 0 deletions
@@ -0,0 +1,21 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
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->where('id', $value);
});
}
}
@@ -0,0 +1,21 @@
<?php
namespace App\Classes\General\Eloquent\Filters;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;
class isPublished implements Filter
{
/**
* @param Builder $builder
* @param $value
* @return Builder|mixed
*/
public static function apply(Builder $builder, $value)
{
return $builder->whereDate('starting_on', '<=', Carbon::now())
->whereDate('ending_on', '>=', Carbon::now());
}
}