<?php

namespace Tricks\LaravelTools\Traits;

use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;

/**
 * @template TModel of Model
 */
trait HasActiveScope
{
    /**
     * @param  Builder<TModel>  $query
     * @return Builder<TModel>
     */
    public function scopeActive(Builder $query): Builder
    {
        if (request()->has('preview')) {
            return $query;
        }

        return $query->where('active', true);
    }
}
