@vlauciani Inheritance or trait.
Mar 7, 2015
6
Level 1
Using one "Accessor" in more then one Model
Hi all
I need to execute a simple PHP 'round' function on Latitude and Longitude attributes that are stored in differente MySQL tables.
Now I've two methods:
class Restaurant extends Model {
public function getLonAttribute($value)
{
return round($value, 3);
}
public function getLatAttribute($value)
{
return round($value, 3);
}
}
and
class Bar extends Model {
public function getLonAttribute($value)
{
return round($value, 3);
}
public function getLatAttribute($value)
{
return round($value, 3);
}
}
I don't want to repeat these functions for each Model where I need to 'round' the Latitude and Longitude; what is the best practice to write It one time and inherited these functions into the Models?
Please or to participate in this conversation.