user1985273
user1985273

Reputation: 1967

Laravel array in lang

Is it possible to get an array element from Laravel lang files?

For example if i have a following array under resources/lang/en/my.php:

<?php

return [
  'fruit' => [1 => 'apple', 2 => 'orange', 3 => 'whatever'],
];

and now under my blade view i want to display a fruit a user has chosen:

@lang('my.fruits')[2]

... but this doesn't work.

How to get the second element of that array in my view?

Upvotes: 1

Views: 1881

Answers (2)

Stack Oriflame
Stack Oriflame

Reputation: 1

__('my.fruit.2'); $orange = trans('my.fruit.2');

Upvotes: 0

Dan
Dan

Reputation: 5358

Try @lang("my.fruit.1"). @lang uses the dot notation so even numeric indexes should work.

Upvotes: 4

Related Questions