Added: language to User profile (DB)

The language were set only on session. But now it is
stored with user profile, on DB.

It is important as now I can send alert e-mails to each
user on their own languages and not the activer
user language.

Also, wherever the user logs out and logs in again,
it will see the same site locale.
This commit is contained in:
2018-10-02 23:53:35 -03:00
parent 8157a183c7
commit 954820f46b
8 changed files with 193 additions and 16 deletions

View File

@@ -32,9 +32,9 @@ class AlertReturnedItem
{
if ($event->item->waiting_user_id) {
$user = User::find($event->item->waiting_user_id);
Mail::to($user)->send(
new ItemAvailable($user->name, $event->item)
);
Mail::to($user)
->locale($user->language)
->send(new ItemAvailable($user->name, $event->item));
}
}
}

View File

@@ -0,0 +1,34 @@
<?php
namespace App\Listeners;
use App\User;
use IlluminateAuthEventsLogin;
use Illuminate\Queue\InteractsWithQueue;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Auth\Events\Login;
class SetLanguage
{
/**
* Create the event listener.
*
* @return void
*/
public function __construct()
{
//
}
/**
* Handle the event.
*
* @param IlluminateAuthEventsLogin $event
* @return void
*/
public function handle(Login $event)
{
session(['lang' => User::loggedIn()->language]);
session()->save();
}
}