Add support for protected Attribute accessors (#1339)

* Add support for protected Attribute accessors

* Fix formatting

* Prevent accessors methods marked as private from being added

* Exclude specific accessors based on trait instead of class

* Add changelog entry

* Add clarifying comment

* Fix accessor attributes not working on PHP < 8.1

* Reintroduce method variable to reduce PR clutter

* Change variable name to reduce PR clutter

* Update CHANGELOG.md

---------

Co-authored-by: Barry vd. Heuvel <[email protected]>
Co-authored-by: Barry vd. Heuvel <[email protected]>
This commit is contained in:
Hans van Luttikhuizen-Ross
2023-02-20 09:44:01 +01:00
committed by GitHub
co-authored by Barry vd. Heuvel Barry vd. Heuvel
parent aa1aa66ee6
commit 39885645b9
6 changed files with 53 additions and 25 deletions
@@ -20,7 +20,7 @@ use Illuminate\Database\Eloquent\Model;
*/
class Simple extends Model
{
public function name(): Attribute
protected function name(): Attribute
{
return new Attribute(
function (?string $name): ?string {
@@ -40,7 +40,7 @@ class Simple extends Model
*
* @return \Illuminate\Database\Eloquent\Casts\Attribute
*/
public function notAnAttribute()
protected function notAnAttribute()
{
return new Attribute(
function (?string $value): ?string {