John Davidson

php - In Laravel8 cant use Lang method

0 comments
Message:


I want to use Laravel Lang method in with parameters. But it is giving error.


return view('backoffice/index')
->with('orderstatus','{{Lang::get('saide.version')}}')
->with('paymentstatus',Lang::get('saide.version'));

How can i solve this problem ??


Errors
Class 'App\Http\Controllers\Lang' not found



My Answer:
To use the Lang method in Laravel 8 with parameters, you can do the following:

1. Make sure you have set up your language files properly in the `resources/lang` directory.

2. Use the `__()` helper function to access language strings with parameters. For example:

php
return view('backoffice/index', [
'welcomeMessage' => __('Welcome, :name', ['name' => 'John'])
]);


3. In your language file (e.g. `resources/lang/en/messages.php`), define the language string with placeholders for parameters:

php
return [
'welcome' => 'Welcome, :name',
];


4. Make sure to clear the cache after making changes to language files by running the following command:

bash
php artisan cache:clear


By following these steps, you should be able to use the Lang method in Laravel 8 with parameters successfully.

Rate this post

5 of 5 based on 8559 votes

Comments




© 2024 Hayatsk.info - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us