orlyapps / nova-belongsto-depend

Larave Nova BelongsTo Field with Dependcy
MIT License
182 stars 65 forks source link

How to display custom attribute on select option #44

Closed PrafullaKumarSahu closed 5 years ago

PrafullaKumarSahu commented 5 years ago

I have created an extra attribute to my Address model like

protected $appends = ['resourceTitle'];

    public function getResourceTitleAttribute()
    {
       return $this->attributes['building_number'] . ', ' . $this->attributes['street'] . ', ' . $this->attributes['city'] . ', ' . $this->attributes['country'] . ', ' . $this->attributes['postcode'];
    }

and set the resource title as $title = 'resourceTitle'; and want that in select box, it is just similar to another question you have answered, but seems not working for me, can you give me any clue on it?

PrafullaKumarSahu commented 5 years ago

Update, I am getting error SQLSTATE[42S22]: Column not found: 1054 Unknown column 'resourceTitle' in 'field list' (SQL: selectid,resourceTitlefromaddresseswhereaddresses.customer_id= 1 andaddresses.customer_idis not null).

PrafullaKumarSahu commented 5 years ago

I solved the issue, In customer address $customer->addresses()->get(['id','building_number', 'street', 'city', 'country', 'postcode'] I need to pull all columns that is used in resourceTitle and that is working fine.