get the key of local in laravel trans

Viewed 661

and i need something thats if i want to get use locale in laravel i did this ..

{{trans('language.add')}}
{{trans('language.my_word')}}
{{trans('language.save')}}
{{trans('language.edit_file')}}

and the locale language file is like this ..

<?php
return 
[
    'add' => 'Add',
    'my_word' => 'Any thing here',
    'save' => 'Save !',
    'edit_file' => 'Edit File',
]

now if i did this code in the blade

{{trans('language.edit_file')}}

the result will be

'Edit File'

now my question is how can i get the key using the word .. i mean how can i access edit_file using Edit File i want to access the value Instead of key to access the key thanks ..

2 Answers

use array_flip.

The array_flip() function is used to exchange the keys with their associated values in an array.

$languages = Lang::get('language');
$languagesFlip = array_flip($languages);

You can try something like this:

{{array_search('Edit file',trans('language'))}}

The result will be edit_file

I hope that is what you need.

Related