Laravel has a
Just had similar issue, for me Eloquent Accessors and mutators worked the best. For this question it would go like:
namespace App;
use Illuminate\Database\Eloquent\Model;
class Customer extends Model
{
/**
* @var array
*/
protected $phoneTypes = [
'Cellular',
'Home',
'Work'
];
/**
* @param int $value
* @return string|null
*/
public function getPhoneTypeAttribute($value)
{
return Arr::get($this->phoneTypes, $value);
}
}
Please note that in database you should save numeric values, where 0 is cell, 1 is home and 2 is work. Secondly it would be wise to use translations here instead protected property.