Skip to content

Commit 46bcfe2

Browse files
authored
AutoCast flags (#48)
* Boolean flags auto-casting * Timestamp flags auto-casting
1 parent 8dafd67 commit 46bcfe2

File tree

83 files changed

+687
-350
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

83 files changed

+687
-350
lines changed

CHANGELOG.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to `laravel-eloquent-flag` will be documented in this file.
77
### Added
88

99
- Laravel 5.8 support
10+
- Flag fields auto-casting
1011

1112
### Changed
1213

@@ -15,8 +16,8 @@ All notable changes to `laravel-eloquent-flag` will be documented in this file.
1516

1617
### Removed
1718

18-
- PHP 5.6, 7.0 support
19-
- Laravel 5.2, 5.3, 5.4 support
19+
- Dropped PHP 5.6, 7.0 support
20+
- Dropped Laravel 5.2, 5.3, 5.4, 5.5, 5.6 support
2021

2122
## [4.0.0] - 2018-09-09
2223

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ Eloquent boolean & timestamp flagged attributes behavior. Enhance Eloquent Model
3838
- Each flag adds global query scopes to models.
3939
- 2 logical groups of flags: `Classic`, `Inverse`.
4040
- 2 types of flags: `Boolean`, `Timestamp`.
41+
- Flag fields auto-casting to `bool` & `DateTime`.
4142
- Following PHP Standard Recommendations:
4243
- [PSR-1 (Basic Coding Standard)](http://www.php-fig.org/psr/psr-1/).
4344
- [PSR-2 (Coding Style Guide)](http://www.php-fig.org/psr/psr-2/).
@@ -91,6 +92,8 @@ Omitted entities could be retrieved by using special global scope methods, uniqu
9192

9293
> **Example:** If your `Article` model has `PublishedAt` flag then `Article::get()` will return you only published records. When you need to get only unpublished records you could call `Article::onlyUnpublished()->get()` and `Article::withUnpublished()->get()` will return you published and unpublished articles as well.
9394
95+
Helper traits will automatically cast flag attributes to a `DateTime` / `Carbon` instance or `bool` for you.
96+
9497
## Installation
9598

9699
Pull in the package through Composer.

composer.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,14 +54,14 @@
5454
},
5555
"require": {
5656
"php": "^7.1.3",
57-
"illuminate/database": "5.5.*|5.6.*|5.7.*|5.8.*"
57+
"illuminate/database": "5.7.*|5.8.*"
5858
},
5959
"require-dev": {
6060
"friendsofphp/php-cs-fixer": "^2.10",
6161
"mockery/mockery": "^1.0",
62-
"orchestra/database": "~3.5.0|~3.6.0|~3.7.0|~3.8.0",
63-
"orchestra/testbench": "~3.5.0|~3.6.0|~3.7.0|~3.8.0",
64-
"phpunit/phpunit": "^5.7|^6.2|^7.0|^8.0"
62+
"orchestra/database": "~3.7.0|~3.8.0",
63+
"orchestra/testbench": "~3.7.0|~3.8.0",
64+
"phpunit/phpunit": "^7.0|^8.0"
6565
},
6666
"autoload": {
6767
"psr-4": {

src/Traits/Classic/HasAcceptedAtHelpers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
trait HasAcceptedAtHelpers
1919
{
20+
public function initializeHasAcceptedAtHelpers(): void
21+
{
22+
$this->dates[] = 'accepted_at';
23+
}
24+
2025
/**
2126
* Set accepted flag.
2227
*

src/Traits/Classic/HasAcceptedFlagHelpers.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
trait HasAcceptedFlagHelpers
1717
{
18+
public function initializeHasAcceptedFlagHelpers(): void
19+
{
20+
$this->casts['is_accepted'] = 'boolean';
21+
}
22+
1823
/**
1924
* Set accepted flag.
2025
*
@@ -46,7 +51,7 @@ public function unsetAcceptedFlag()
4651
*/
4752
public function isAccepted(): bool
4853
{
49-
return (bool) $this->getAttributeValue('is_accepted');
54+
return $this->getAttributeValue('is_accepted');
5055
}
5156

5257
/**

src/Traits/Classic/HasActiveFlagHelpers.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
trait HasActiveFlagHelpers
1717
{
18+
public function initializeHasActiveFlagHelpers(): void
19+
{
20+
$this->casts['is_active'] = 'boolean';
21+
}
22+
1823
/**
1924
* Set active flag.
2025
*
@@ -46,7 +51,7 @@ public function unsetActivatedFlag()
4651
*/
4752
public function isActivated(): bool
4853
{
49-
return (bool) $this->getAttributeValue('is_active');
54+
return $this->getAttributeValue('is_active');
5055
}
5156

5257
/**

src/Traits/Classic/HasApprovedAtHelpers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
trait HasApprovedAtHelpers
1919
{
20+
public function initializeHasApprovedAtHelpers(): void
21+
{
22+
$this->dates[] = 'approved_at';
23+
}
24+
2025
/**
2126
* Set approved flag.
2227
*

src/Traits/Classic/HasApprovedFlagHelpers.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
trait HasApprovedFlagHelpers
1717
{
18+
public function initializeHasApprovedFlagHelpers(): void
19+
{
20+
$this->casts['is_approved'] = 'boolean';
21+
}
22+
1823
/**
1924
* Set approved flag.
2025
*
@@ -46,7 +51,7 @@ public function unsetApprovedFlag()
4651
*/
4752
public function isApproved(): bool
4853
{
49-
return (bool) $this->getAttributeValue('is_approved');
54+
return $this->getAttributeValue('is_approved');
5055
}
5156

5257
/**

src/Traits/Classic/HasInvitedAtHelpers.php

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,11 @@
1717

1818
trait HasInvitedAtHelpers
1919
{
20+
public function initializeHasInvitedAtHelpers(): void
21+
{
22+
$this->dates[] = 'invited_at';
23+
}
24+
2025
/**
2126
* Set invited flag.
2227
*

src/Traits/Classic/HasInvitedFlagHelpers.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,11 @@
1515

1616
trait HasInvitedFlagHelpers
1717
{
18+
public function initializeHasInvitedFlagHelpers(): void
19+
{
20+
$this->casts['is_invited'] = 'boolean';
21+
}
22+
1823
/**
1924
* Set invited flag.
2025
*
@@ -46,7 +51,7 @@ public function unsetInvitedFlag()
4651
*/
4752
public function isInvited(): bool
4853
{
49-
return (bool) $this->getAttributeValue('is_invited');
54+
return $this->getAttributeValue('is_invited');
5055
}
5156

5257
/**

0 commit comments

Comments
 (0)