1

I want to make standard request for laravel localization file: animals.php

which looks like:

<?php 
return [
    'dog' => 'dog trans',
    'cat' => 'cat trans',
    'super-mutant-spider' => 'super-mutant-spider trans',
];

Now when I'm accessing this, I'm simply writing:

trans('animals.dog') -> gives dog trans etc.

this is fine,

now I want to make it depend on the user variable animal:

so when $user->animal is 'dog' I want dog trans result.

so when I try: trans('animals.$user->animal') it will not work

How can I code it?

gileneusz
  • 1,435
  • 8
  • 30
  • 51

1 Answers1

5

This is basic string concatenating.

What you need is basically this: trans('animals.' . $user->animal)

You have detailed explanation on PHP - concatenate or directly insert variables in string

Marwelln
  • 28,492
  • 21
  • 93
  • 117