0

I use Laravel Framework, and found this issue:

$var = ($userdata->age > 18 ? 'OK' : '@lang("basics.no_access")');

Of course I want to get the nice text from resources/lang/en/basics.php and not echo the '@lang("basics.no_access")' text.

How can I do this?

0

1 Answer 1

1

@lang works only within blade templates.

Use lang::get() which is the correct way to look up a language key outside a template:

When you pass Lang::get() a key, it looks up the key in the translation tables for the current locale. If no match is found, the original key is returned.

Sign up to request clarification or add additional context in comments.

2 Comments

Looking good, but now I get FatalErrorException in MyController.php line 30: Class 'App\Http\Controllers\Lang' not found. How can I get this Lang controller? Sorry, I'm really newbie for Laravel.
Sorry, use Lang; give me the soution :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.