n7olkachev/laravel-accessors

Use Laravel-like accessors in your classes

v1.0.0 2017-08-28 19:25 UTC

This package is auto-updated.

Last update: 2024-11-23 21:51:19 UTC


README

Code quality Licence Build Status

This package gives you ability to use getFooBarAttribute and setFooBarAttribute methods in your classes with one trait.

Examples

class User
{
    use Accessors;
    
    protected $name;
    
    public function __construct($name)
    {
        $this->name = $name;
    }
    
    public function getNameAttribute()
    {
        return $this->name;
    }
    
    public function setNameAttribute($name)
    {
        $this->name = $name;
    }
}

$user = new User('Nick');
echo $user->name; // calls getNameAttribute
$user->name = 'Not Nick' // calls setNameAttribute

Instalation

$ composer require n7olkachev/laravel-accessors

In your class:

class User
{
    use Accessors;
}

Testing

$ composer test

Credits

Sponsored by

https://websecret.by/

Web agency based in Minsk, Belarus

License

The MIT License (MIT)