-
-
Notifications
You must be signed in to change notification settings - Fork 30
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Restores the "addVisible" / "addHidden" methods removed in Laravel 7
It is recommended to use "makeVisible" / "makeHidden" in new code going forward. Fixes wintercms/winter#567
- Loading branch information
1 parent
9e2eca0
commit 1643791
Showing
3 changed files
with
110 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
<?php | ||
|
||
namespace Winter\Storm\Database\Concerns; | ||
|
||
/** | ||
* Hides and shows attributes for serialization. | ||
*/ | ||
trait HidesAttributes | ||
{ | ||
/** | ||
* Add hidden attributes for the model. | ||
* | ||
* This restores the `addHidden` method that was removed from Laravel 7 onwards. It is however recommended to use | ||
* the `makeHidden` method going forward. | ||
* | ||
* @param array|string|null $attributes | ||
*/ | ||
public function addHidden($attributes = null): void | ||
{ | ||
$this->hidden = array_merge( | ||
$this->hidden, | ||
is_array($attributes) ? $attributes : func_get_args() | ||
); | ||
} | ||
|
||
/** | ||
* Add visible attributes for the model. | ||
* | ||
* This restores the `addVisible` method that was removed from Laravel 7 onwards. It is however recommended to use | ||
* the `makeVisible` method going forward. | ||
* | ||
* @param array|string|null $attributes | ||
*/ | ||
public function addVisible($attributes = null): void | ||
{ | ||
$this->visible = array_merge( | ||
$this->visible, | ||
is_array($attributes) ? $attributes : func_get_args() | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Just as a bit of trivia - this test as well as the one below was 90% written by GitHub Copilot. Actually did very well with creating a unit test case from scratch :)