Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

marufalom's avatar

Localize enum or set data type on Laravel

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?

0 likes
2 replies
Sinnbeck's avatar
$translation = trans('app.person_status_' . $person->status);
1 like

Please or to participate in this conversation.