Skip to content

Commit

Permalink
Merge pull request #5 from lacodix/feat/github-actions
Browse files Browse the repository at this point in the history
Feat/GitHub actions
  • Loading branch information
renky authored Feb 20, 2024
2 parents ac8ac6a + 49a0bb0 commit 57ff074
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 25 deletions.
3 changes: 1 addition & 2 deletions docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,4 @@ You can install the package via composer:
composer require lacodix/laravel-global-or-scope
```

There are noe resources, no service providers, no config files.
Just start using.
There are no resources, no config files. Just start using.
19 changes: 10 additions & 9 deletions docs/usage/advanced-usage.md
Original file line number Diff line number Diff line change
@@ -1,23 +1,25 @@
---
title: Advanced Usage
weight: 1
weight: 3
---

Finally you can use our internal OrScope directly. This can be useful for all cases where
you already have multiple scope classes that you want to combine with an or.

```php
use Lacodix\LaravelGlobalOrScope\Scopes\OrScope;

$orScope = new OrScope([new Scope1()), new Scope2())])

$query->withGlobalScope('or_scope', $orScope);
```

This is exactly what our `withGlobalOrScopes` on the query builder does. But with that in mind
This is exactly what our `withGlobalOrScopes` method on the query builder does. But with that in mind
you can even apply more complex scope combinations like this:

```php
$orScope1 = new OrScope([new Scope1()), new Scope2())])
$orScope2 = new OrScope([new Scope31()), new Scope4())])
$orScope2 = new OrScope([new Scope3()), new Scope4())])

$query->withGlobalScope('or_scope1', $orScope1);
$query->withGlobalScope('or_scope2', $orScope2);
Expand All @@ -30,7 +32,9 @@ This will result in a query applying

### Scope exchange

Sometimes you already have applied one Scope to your model like this on the classic way:
Sometimes you already have applied one Scope to your model on the classic way:
But for some cases in your application you need this scope combined with another by or condition.
Just do this:

```php
class Post extends Model
Expand All @@ -43,13 +47,10 @@ class Post extends Model
}
}
```

But for some cases in your application you need this scope combined with another by or condition.
Just do this:

First we remove the solo Scope1::class and re add it in the second step, combined with a new one via OrScope.
```php
Post::query()
->withoutGlobalScope(Scope1::class)
->withGlobalOrScopes([new Scope1(), new Scope2()]);
```
First we remove the solo Scope1::class and re add it in the second step, combined with a new one via OrScope.

2 changes: 1 addition & 1 deletion docs/usage/disable-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,5 +35,5 @@ Post::query()->removedOrScopes();
If you want to disable all global scopes for the whole request, just call

```php
Post::clearGlobalOrScope();
Post::clearGlobalOrScopes();
```
14 changes: 7 additions & 7 deletions docs/usage/register-scopes.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@ title: Register Global Or Scopes
weight: 1
---

There are multiple ways of registering global scopes that use or condition.
There are multiple ways of registering global scopes that shall use or conditions.

## addGlobalOrScopes

The most common use case is registering a global scope on booting the model.
Therefor just add our Trait to your model and finally add the global scopes to your model.

ATTENTION: to make our trait work, the global scopes must be registered before the
> ATTENTION: to make our trait work, the global scopes must be registered before the
boot()-method of the base Eloquent model is called. The easy way is using
the booting-method of your model.

Expand All @@ -26,7 +26,7 @@ class Post extends Model
}
```

But you can also go with the boot method but be sure to run parent::boot()
But you can also go with the boot method if you ensure to run parent::boot()
after registering the global scopes.

```php
Expand All @@ -45,7 +45,7 @@ class Post extends Model

## addGlobalOrScope

You can also add one single scope, what doesn't make really sense. But maybe
You can also add one single scope, what doesn't make really sense. But if
you want to use a loop for registering it might be the correct way.

```php
Expand Down Expand Up @@ -97,15 +97,15 @@ class Post extends Model

## withGlobalOrScopes

You can also add global scopes with or condition on the fly with using the query builder.
You can also add global scopes with or condition on the fly by using the query builder.
In this case you even don't need the GlobalOrScope trait. You can just apply scopes on
every query:
every model query:

```php
Post::query()->withGlobalOrScopes([new Scope1, new Scope2]);
```

Attention: like in laravels base functionality (withGlobalScope) you need to add initialized
> ATTENTION: like in laravels base functionality (withGlobalScope) you need to add initialized
scopes, not only classnames.

## Combining with normal global scopes
Expand Down
2 changes: 1 addition & 1 deletion src/Traits/GlobalOrScope.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public static function bootGlobalOrScope(): void
}
}

public static function clearGlobalOrScope(): void
public static function clearGlobalOrScopes(): void
{
static::$globalOrScopes = [];
}
Expand Down
10 changes: 5 additions & 5 deletions tests/Unit/GlobalOrScopesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ class EloquentQueryGlobalOrScopesTestModel extends Model

public static function booting(): void
{
static::clearGlobalOrScope();
static::clearGlobalOrScopes();
}
}

Expand All @@ -132,7 +132,7 @@ class EloquentGlobalOrScopesTestModel extends Model

public static function booting(): void
{
static::clearGlobalOrScope();
static::clearGlobalOrScopes();
}

public static function boot()
Expand All @@ -151,7 +151,7 @@ class EloquentClassNameGlobalOrScopesTestModel extends Model

public static function booting(): void
{
static::clearGlobalOrScope();
static::clearGlobalOrScopes();
}

public static function boot()
Expand All @@ -170,7 +170,7 @@ class EloquentClosureGlobalOrScopesTestModel extends Model

public static function booting(): void
{
static::clearGlobalOrScope();
static::clearGlobalOrScopes();
}

public static function boot(): void
Expand Down Expand Up @@ -205,7 +205,7 @@ class EloquentGlobalOrScopesArrayTestModel extends Model

public static function booting(): void
{
static::clearGlobalOrScope();
static::clearGlobalOrScopes();
}

public static function boot()
Expand Down

0 comments on commit 57ff074

Please sign in to comment.