0👍
Credits to rodrogo.pedra
You can have a virtual accessor for the values label:
class TradingModel extends Model
{
// tells Laravel to append this virtual column to JSON output
protected $appends = ['trading_status_label'];
public function getTradingStatusLabelAttribute()
{
return [
0 => 'trading status 1',
1 => 'trading status 2',
][$this->trading_status_id];
}
}
Think of vue’s computed property, but for Laravel.
This way you can use trading_status_label for display in the table and keep using trading_status_id original value in forms or data related tasks.
- [Vuejs]-How to call a method in a Vue component from programmatically inserted component
- [Vuejs]-Vue async bind data
Source:stackexchange.com