n7olkachev / laravel-accessors by n7olkachev

Use Laravel-like accessors in your classes
651
11
3
Package Data
Maintainer Username: n7olkachev
Maintainer Contact: n7olkachev@gmail.com (Nikita Tolkachev)
Package Create Date: 2017-08-28
Package Last Update: 2017-08-28
Language: PHP
License: MIT
Last Refreshed: 2024-11-21 03:00:46
Package Statistics
Total Downloads: 651
Monthly Downloads: 1
Daily Downloads: 0
Total Stars: 11
Total Watchers: 3
Total Forks: 0
Total Open Issues: 0

Laravel Accessors

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)