Skip to content
Automatically convert your Eloquent scopes to boolean check methods.
PHP
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
src Initial commit Feb 6, 2020
tests Initial commit Feb 6, 2020
.editorconfig Initial commit Feb 6, 2020
.gitattributes Initial commit Feb 6, 2020
.gitignore Initial commit Feb 6, 2020
.phpunit.result.cache Initial commit Feb 6, 2020
.scrutinizer.yml Initial commit Feb 6, 2020
.styleci.yml Initial commit Feb 6, 2020
.travis.yml wip Feb 6, 2020
CHANGELOG.md Initial commit Feb 6, 2020
CONTRIBUTING.md Initial commit Feb 6, 2020
LICENSE.md Initial commit Feb 6, 2020
README.md Initial commit Feb 6, 2020
composer.json wip Feb 6, 2020
phpunit.xml.dist Initial commit Feb 6, 2020

README.md

Laravel Scope Checks

Automatically convert your Eloquent scopes to boolean check methods.

Latest Version on Packagist Build Status Quality Score Total Downloads

This package allows you to automatically call all your eloquent model scope methods as checks.

class User extends Model
{
    use HasScopeChecks;
    
    public function scopeActive($query)
    {
        $query->where('active', true);
    }
    
    public function scopeActive($query)
    {
        return $query->where('active', 1);
    }
}

// Now you can call your scope check using:
$user->isActive();

Installation

You can install the package via composer:

composer require beyondcode/laravel-scope-checks

Usage

All you need to do to be able to call your scopes as check methods is add the HasScopeChecks trait to your eloquent model.

use \BeyondCode\LaravelScopeChecks\HasScopeChecks;

class Post {
    use HasScopeChecks;
    
    public function scopePublished($query)
    {
        return $query->where('active', 1);
    }
    
    public function scopeMinimumRating($query, $rating = 5)
    {
        return $query->where('rating', '>=', $rating);
    }
}

You can either call your check methods using the is or the has naming prefix on your model instances. For example:

$post->isPublished();
$post->hasMinimumRating();

When you make use of dynamic scopes (like the scopeRating method), you can also pass the additional scope parameters to the check methods:

$post->isMinimumRating(1);
$post->hasMinimumRating(1);

Testing

composer test

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security

If you discover any security related issues, please email marcel@beyondco.de instead of using the issue tracker.

Credits

License

The MIT License (MIT). Please see License File for more information.

You can’t perform that action at this time.