Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,18 @@

All notable changes to `laravel-eloquent-flag` will be documented in this file.

## 2.1.0 - 2016-01-04

- `is_closed` inverse boolean flag added.

## 2.0.0 - 2016-01-04

#### Breaking changes
### Breaking changes

- Namespaces of flag's traits received `Classic` at the end: `Cog\Flag\Traits\Classic`.
- Namespaces of flag's scopes received `Classic` at the end: `Cog\Flag\Scopes\Classic`.

#### Added
### Added

- `Inverse Logic` flags group. Hides entities if flag not set.
- `is_expired` inverse boolean flag added.
Expand Down
4 changes: 2 additions & 2 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ Due to time constraints, we are not always able to respond as quickly as we woul

This project comes with a configuration file for php-cs-fixer (.php_cs) that you can use to (re)format your sourcecode for compliance with this project's coding guidelines:

```shell
```sh
vendor/bin/php-cs-fixer fix
```

## PHPUnit tests

The phpunit script can be used to invoke the PHPUnit test runner:

```shell
```sh
vendor/bin/phpunit
```

Expand Down
144 changes: 98 additions & 46 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,16 @@ Eloquent flagged attributes behavior. Add commonly used flags to models very qui

## Available flags list

| Trait name | Database columns | Flag type | Logic |
| ---------- | ---------------- | --------- | ----- |
| `HasAcceptedFlag` | `is_accepted` | Boolean | Classic |
| `HasActiveFlag` | `is_active` | Boolean | Classic |
| `HasApprovedFlag` | `is_approved` | Boolean | Classic |
| `HasExpiredInverseFlag` | `is_expired` | Boolean | Inverse |
| `HasKeptFlag` | `is_kept` | Boolean | Classic |
| `HasPublishedFlag` | `is_published` | Boolean | Classic |
| `HasVerifiedFlag` | `is_verified` | Boolean | Classic |
| Trait name | Logic | Database columns | Flag type |
| ---------- | ----- | ---------------- | --------- |
| `HasAcceptedFlag` | Classic | `is_accepted` | Boolean |
| `HasActiveFlag` | Classic | `is_active` | Boolean |
| `HasApprovedFlag` | Classic | `is_approved` | Boolean |
| `HasClosedFlag` | Inverse | `is_closed` | Boolean |
| `HasExpiredFlag` | Inverse | `is_expired` | Boolean |
| `HasKeptFlag` | Classic | `is_kept` | Boolean |
| `HasPublishedFlag` | Classic | `is_published` | Boolean |
| `HasVerifiedFlag` | Classic | `is_verified` | Boolean |

## How it works

Expand Down Expand Up @@ -81,32 +82,32 @@ class Post extends Model

#### Get only active models

```shell
```php
Post::all();
Post::withoutInactive();
```

#### Get only inactive models

```shell
```php
Post::onlyInactive();
```

#### Get active + inactive models

```shell
```php
Post::withInactive();
```

#### Activate model

```shell
```php
Post::where('id', 4)->activate();
```

#### Deactivate model

```shell
```php
Post::where('id', 4)->deactivate();
```

Expand All @@ -132,32 +133,32 @@ class Post extends Model

#### Get only accepted models

```shell
```php
Post::all();
Post::withoutUnaccepted();
```

#### Get only unaccepted models

```shell
```php
Post::onlyUnaccepted();
```

#### Get accepted + unaccepted models

```shell
```php
Post::withUnaccepted();
```

#### Accept model

```shell
```php
Post::where('id', 4)->accept();
```

#### Deactivate model

```shell
```php
Post::where('id', 4)->unaccept();
```

Expand All @@ -183,32 +184,32 @@ class Post extends Model

#### Get only approved models

```shell
```php
Post::all();
Post::withoutUnapproved();
```

#### Get only unapproved models

```shell
```php
Post::onlyUnapproved();
```

#### Get approved + unapproved models

```shell
```php
Post::withUnapproved();
```

#### Approve model

```shell
```php
Post::where('id', 4)->approve();
```

#### Unapprove model

```shell
```php
Post::where('id', 4)->unapprove();
```

Expand All @@ -234,32 +235,32 @@ class Post extends Model

#### Get only published models

```shell
```php
Post::all();
Post::withoutUnpublished();
```

#### Get only unpublished models

```shell
```php
Post::onlyUnpublished();
```

#### Get published + unpublished models

```shell
```php
Post::withUnpublished();
```

#### Publish model

```shell
```php
Post::where('id', 4)->publish();
```

#### Unpublish model

```shell
```php
Post::where('id', 4)->unpublish();
```

Expand All @@ -285,32 +286,32 @@ class Post extends Model

#### Get only verified models

```shell
```php
Post::all();
Post::withoutUnverified();
```

#### Get only unverified models

```shell
```php
Post::onlyUnverified();
```

#### Get verified + unverified models

```shell
```php
Post::withUnverified();
```

#### Verify model

```shell
```php
Post::where('id', 4)->verify();
```

#### Unverify model

```shell
```php
Post::where('id', 4)->unverify();
```

Expand Down Expand Up @@ -361,38 +362,38 @@ By default all records that have a `is_kept` equals to 0 will be excluded from y

#### Get only kept models

```shell
```php
Post::all();
Post::withoutUnkept();
```

#### Get only unkept models

```shell
```php
Post::onlyUnkept();
```

#### Get kept + unkept models

```shell
```php
Post::withUnkept();
```

#### Keep model

```shell
```php
Post::where('id', 4)->keep();
```

#### Unkeep model

```shell
```php
Post::where('id', 4)->unkeep();
```

#### Get unkept models which older than hours

```shell
```php
Post::onlyUnkeptOlderThanHours(4);
```

Expand Down Expand Up @@ -420,40 +421,91 @@ class Post extends Model

#### Get only not expired models

```shell
```php
Post::all();
Post::withoutExpired();
```

#### Get only expired models

```shell
```php
Post::onlyExpired();
```

#### Get expired + not expired models

```shell
```php
Post::withExpired();
```

#### Set expire flag to model

```shell
```php
Post::where('id', 4)->expire();
```

#### Remove expire flag from model

```shell
```php
Post::where('id', 4)->unexpire();
```

### Setup a closable model

```php
<?php

namespace App\Models;

use Cog\Flag\Traits\Inverse\HasClosedFlag;
use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
use HasClosedFlag;
}
```

*Model must have boolean `is_closed` column in database table.*

### Available functions

#### Get only not closed models

```php
Post::all();
Post::withoutClosed();
```

#### Get only closed models

```php
Post::onlyClosed();
```

#### Get closed + not closed models

```php
Post::withClosed();
```

#### Set close flag to model

```php
Post::where('id', 4)->close();
```

#### Remove close flag from model

```php
Post::where('id', 4)->unclose();
```

## Testing

Run the tests with:

```shell
```sh
vendor/bin/phpunit
```

Expand Down
Loading