cybercog / laravel-eloquent-flag

Laravel Eloquent boolean & timestamp flagged attributes behavior.
https://komarev.com/sources/laravel-eloquent-flag
MIT License
133 stars 21 forks source link

Separate flag scopes & helper methods #13

Closed antonkomarev closed 7 years ago

antonkomarev commented 7 years ago

Each flag has root trait Has{Name}Flag which will use:

antonkomarev commented 7 years ago

The only thing left to decide, is current methods should be placed in HasKeptFlagScope or HasKeptFlagHelpers trait.

public function scopeOnlyUnkeptOlderThanHours(Builder $builder, $hours)
{
    return $builder->onlyUnkept()
        ->where(static::getCreatedAtColumn(), '<=', Carbon::now()->subHours($hours)->toDateTimeString());
}

Right now it's in HasKeptFlagScope trait, but this is helper, not a global scope. Placed in scope because it's depends on onlyUnkept() method and if Scope trait wouldn't be loaded by developer - this method will be broken.

Solutions:

  1. Left all Global Scope dependent methods in Scope trait.
  2. Make this method to ignore global scope only if it's exists and used.