Skip to content

Commit c6126c4

Browse files
committed
feat: move ActiveScope from core
Moved ActiveScope class from core and added catalogue as a dev dep to allow testing the scope.
1 parent cab2a69 commit c6126c4

File tree

3 files changed

+35
-0
lines changed

3 files changed

+35
-0
lines changed

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@
4848
"spatie/laravel-package-tools": "^1.19"
4949
},
5050
"require-dev": {
51+
"eclipsephp/catalogue-plugin": "dev-main",
5152
"laravel/pint": "^1.21",
5253
"orchestra/testbench": "^10.1",
5354
"pestphp/pest": "^3.7",
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Eclipse\Common\Foundation\Models\Scopes;
4+
5+
use Illuminate\Database\Eloquent\Builder;
6+
use Illuminate\Database\Eloquent\Model;
7+
use Illuminate\Database\Eloquent\Scope;
8+
9+
class ActiveScope implements Scope
10+
{
11+
/**
12+
* Apply the scope to a given Eloquent query builder.
13+
*/
14+
public function apply(Builder $builder, Model $model): void
15+
{
16+
$builder->where('is_active', 1);
17+
}
18+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
<?php
2+
3+
use Eclipse\Catalogue\Models\Group;
4+
use Eclipse\Common\Foundation\Models\Scopes\ActiveScope;
5+
6+
test('active scope works', function () {
7+
8+
// Create an inactive product group
9+
$group = Group::factory()->inactive()->create();
10+
11+
// Test scope being applied
12+
expect(Group::where('id', $group->id)->count())->toBe(0);
13+
14+
// Test scope not being applied
15+
expect(Group::withoutGlobalScope(ActiveScope::class)->where('id', $group->id)->count())->toBe(1);
16+
});

0 commit comments

Comments
 (0)