Support the ongoing development of Laravel.io →
Database Eloquent Installation
Last updated 1 year ago.
0

There is a lists() method that can clean up your code to a single line. :)

return Language::lists('translation_es', 'key')->toArray();
0

Thanks thomastkim! That's a nice edit. I removed the toArray() method chained on the end as apparently lists returns an array.

return Language::lists('translation_es', 'key');
Last updated 8 years ago.
0

No problem. :)

I can't test it right now, but it should be a collection. However, if you are making it an ajax call and returning it as a json response (for example), then Laravel will automagically convert it.

Last updated 8 years ago.
0

Interesting. I've also just read that in 5.x it now returns a collection rather than an array, but the code is working without toArray(). This is inside the lang folder, so Laravel itself is consuming the collection to get the correct translation. For example, in my Blade template i'm just doing {!! trans('myLangFile.myNamespace_keyvalue) !!}. I wonder what's going on behind the scenes...

0

Sign in to participate in this thread!

Eventy

Your banner here too?

andyc andyc Joined 30 Nov 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.