Level 102
$translation = trans('app.person_status_' . $person->status);
1 like
Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.
How can I localize a enum fields.
For example persons table as a enum column status which contain student, teacher, parent.
I can translate in blade or resource like this:
$person->status === 'student' ?: trans('app.person_status_student') || $person->status === 'teacher' ?: trans('app.person_status_teacher') || $person->status === 'parent' ?: trans('app.person_status_parent')
This is so odd and will be messy if we have more status value.
Is there any better way to handle this?
Please or to participate in this conversation.