[英]How to pass locale parameter from job into controller?
On laravel site making Http Post request inside of job handle I need to pass locale parameter.在 laravel 网站上制作 Http 在作业句柄内发布请求我需要传递语言环境参数。 And this locale must be used in controller.
并且必须在 controller 中使用此语言环境。
I use astrotomic/laravel-translatable and defined in config/translatable.php with default 'en':我使用 astrotomic/laravel-translatable 并在 config/translatable.php 中定义,默认为“en”:
'locales' => [
'en',
'fr',
...
'locale' => null,
...
<?php
namespace App\Jobs;
class BannersCRUDTest implements ShouldQueue
{
public function handle()
{
$currentLocale = 'fr'; // I path French
App::setLocale($currentLocale);
session()->put('locale', $currentLocale); // That does not work...
$response = Http::post(route('banners.filter' ));
But checking in related Controller with getLocale method I see English但是用 getLocale 方法检查相关的 Controller 我看到英文
class BannerController extends Controller
{
public function filter(): array
{
\Log::info(' -1 BannerController app()->getLocale()::'); // I see 'en' value
\Log::info(app()->getLocale();
...
How have I to pass locale from Job to Controller ? I prefer to use App::setLocale, not as parameter in url of request...
"laravel/framework": "^9.19",
"guzzlehttp/guzzle": "^7.2",
"astrotomic/laravel-translatable": "^11.11",
"mxl/laravel-job": "^1.3",
Thanks in advance!提前致谢!
You use a job (BannersCRUDTest) to set locale from 'en' to 'fr'您使用作业 (BannersCRUDTest) 将区域设置从“en”设置为“fr”
This job of yours is set to be queued.你的这个工作被设置为排队。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.