In my application, I need a lot of getter and setter, and my idea was to generate them from an array, for example:
protected $methods = ['name', 'city'];
With these two parameters, I will need to generate the following methods:
public function getNameAttribute() {
return $this->getName();
}
public function getName($lang = null) {
return $this->getEntityValue('name', $lang);
}
And for the city, the method will be:
public function getCityAttribute() {
return $this->getCity();
}
public function getCity($lang = null) {
return $this->getEntityValue('city', $lang);
}
Of course, I also need to generate a setter (with the same logic).
As you can see, I will need a method with get<variable_name>Attributeand inside this call get<variable_name>, and another (getName) will even return the same method (for each recipient) and simply change the parameter 'name'.
Each method has the same logic, and I would like to generate them "dynamically". I do not know if this is possible.
source
share