n7olkachev / laravel-accessors by n7olkachev

Use Laravel-like accessors in your classes
650
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-04-16 15:04:45
Package Statistics
Total Downloads: 650
Monthly Downloads: 0
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)