2024-07-26 09:35:09 -04:00
|
|
|
<?php
|
|
|
|
|
2025-01-30 00:23:55 -05:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
2024-07-26 09:35:09 -04:00
|
|
|
namespace App\Models\Scopes;
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Builder;
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
use Illuminate\Database\Eloquent\Scope;
|
|
|
|
|
|
|
|
class PublishedScope implements Scope
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Apply the scope to a given Eloquent query builder.
|
2025-01-30 20:49:56 -05:00
|
|
|
*
|
|
|
|
* @param Builder<Model> $builder
|
2024-07-26 09:35:09 -04:00
|
|
|
*/
|
|
|
|
public function apply(Builder $builder, Model $model): void
|
|
|
|
{
|
2024-07-31 14:06:56 -04:00
|
|
|
$builder->whereNotNull($model->getTable().'.published_at')
|
2024-07-31 15:14:22 -04:00
|
|
|
->where($model->getTable().'.published_at', '<=', now());
|
2024-07-26 09:35:09 -04:00
|
|
|
}
|
|
|
|
}
|