shareit/app/User.php
Bruno Fontes 954820f46b
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.
2018-10-02 23:53:35 -03:00

70 lines
1.4 KiB
PHP

<?php
namespace App;
use Auth;
use Illuminate\Notifications\Notifiable;
use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Support\Facades\Request;
class User extends Authenticatable implements MustVerifyEmail
{
use Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $fillable = [
'name', 'email', 'password',
];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
public function products()
{
return $this->hasMany(Product::class);
}
public function items()
{
return $this->belongsToMany(Item::class);
}
/**
* Return the logged in user
*
* @return \App\User
*/
public static function loggedIn()
{
return (new static)->findOrFail(Auth::id());
}
/**
* Set the default website language
* for the acual user
*
* @param string $language The language code
*
* @return void
*/
public static function setLanguage(string $language)
{
if (Auth::check()) {
$user = self::loggedIn();
$user->language = $language;
$user->save();
}
}
}