jeudi 23 janvier 2020

Laravel using accessor to return a country name from country code

I have a table that has country_code and country_name.

Each user in my database has country_code on their account. What I want to do is automatically return the country_name instead of the country_code for that user.

I have setup an accessor in my User model, but it doesn't seem to work.

public function getCountryCodeAttribute($value): string
{
    return Country::firstWhere('country_code', $value)->get('country_name');
}

It keeps still returning the country_code

Any help would be great



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/3aG4HII
via IFTTT

Aucun commentaire:

Enregistrer un commentaire