[Vuejs]-Laravel BootstrapVue CRUD SPA how to make an Accesor that affect only one vue component

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.

Leave a comment