php - Laravel 5.4 translations with constant values -
i'm facing problem translations. i'm pretty new them, never tried add translations project. i've model notifications in laravel 5.4:
// /app/notification.php class notification extends model { const no_status = 0; const sent = 100; const accepted = 200; const error = 300; public static $statuses = [ self::no_status => 'no status', self::sent => 'sent', self::accepted => 'accepted', self::error => 'error', ]; /** * attributes mass assignable. * * @var array */ protected $fillable = [ 'from', 'to', 'status', ]; /** * attributes should hidden arrays. * * @var array */ protected $hidden = [ // ]; /** * attributes should casted native types. * * @var array */ protected $casts = [ 'from' => 'integer', 'status' => 'integer', ]; public function issent() { return $this->status == self::sent; } public function isaccepted() { return $this->status == self::accepted; } public function iserror() { return $this->status == self::error; } public static function statuses() { return self::statuses(); } public function getstatusattribute($value) { return self::$statuses[$value]; } } and have translation file, i'm intended use convert numeric values stored in database status readable text users when see notifications list in view:
// /resources/lang/en/constants.php return [ /* * notifications constants */ 'notification' => [ 'no_status' => 'no status', 'sent' => 'sent', 'accepted' => 'accepted', 'error' => 'error', ], ]; i have getstatusattribute accessor function in model retrieve status code text, can't set value static attribute (obviusly), so:
public static $statuses = [ self::no_status => trans('constants.notification.no_status'), self::sent => trans('constants.notification.sent'), self::accepted => trans('constants.notification.accepted'), self::error => trans('constants.notification.error'), ]; any suggestion how can achieve this?
i want returned property in object becomes translated text, instead translate in view, if possible.
thanks time.
Comments
Post a Comment