Hi everyone I have a little trouble with my code Laravel.
What I do
I have a laravel backend application that serves as a PHP API with which I send account activation emails to the user. When the user of the front-end (Application Vuejs) is registered, an Xhr request is sent with Vue-resource whose header contains a 'Accept-Language' which is the language used by the user's browser.
Back-end side (Laravel) I created a "SetLocale" middleware that gets the value of the 'Accept-Language' of the Xhr query and loads the appropriate language
SetLocale Middleware
<?php
namespace App\Http\Middleware;
use Closure;
class SetLocale
{
/**
* Handle an incoming request.
*
* @param \Illuminate\Http\Request $request
* @param \Closure $next
* @return mixed
*/
public function handle($request, Closure $next)
{
if (!$request->isMethod('OPTIONS')) {
$desiredLocale = $request->getPreferredLanguage();
$locale = locale()->isSupported($desiredLocale) ? $desiredLocale : locale()->fallback();
locale()->set($locale);
}
return $next($request);
}
}
locale() is a helper that I created that configure the user's language.
I use Redis to send queued emails to speed up the xhr query and improve the user experience. However, when Redis wishes to send the e-mail, Since no xhr request is made at this time, the user's language is not configured and Redis sends the e-mail with the Fallback language
What I Want
I want Redis to send the email using the user's language. For example if I am French I want to receive an email in French and not in English
What I got
In this test the default language of my browser is French and here is the email I receive: 
from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2I362i6
via IFTTT
Aucun commentaire:
Enregistrer un commentaire