2018-09-07 23:12:34 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App;
|
|
|
|
|
2018-10-03 02:53:35 +00:00
|
|
|
use Auth;
|
2018-09-07 23:12:34 +00:00
|
|
|
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
2021-05-20 23:37:35 +00:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
2018-09-07 23:12:34 +00:00
|
|
|
|
2018-09-17 14:06:35 +00:00
|
|
|
class User extends Authenticatable implements MustVerifyEmail
|
2018-09-07 23:12:34 +00:00
|
|
|
{
|
|
|
|
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',
|
|
|
|
];
|
2018-09-11 23:48:09 +00:00
|
|
|
|
|
|
|
public function products()
|
|
|
|
{
|
|
|
|
return $this->hasMany(Product::class);
|
|
|
|
}
|
2018-09-12 05:31:03 +00:00
|
|
|
|
|
|
|
public function items()
|
|
|
|
{
|
|
|
|
return $this->belongsToMany(Item::class);
|
|
|
|
}
|
2018-09-19 17:58:10 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Return the logged in user
|
2021-05-20 23:37:35 +00:00
|
|
|
*
|
2018-09-19 17:58:10 +00:00
|
|
|
* @return \App\User
|
|
|
|
*/
|
|
|
|
public static function loggedIn()
|
|
|
|
{
|
2018-10-03 02:53:35 +00:00
|
|
|
return (new static)->findOrFail(Auth::id());
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Set the default website language
|
|
|
|
* for the acual user
|
2021-05-20 23:37:35 +00:00
|
|
|
*
|
2018-10-03 02:53:35 +00:00
|
|
|
* @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();
|
|
|
|
}
|
2018-09-19 17:58:10 +00:00
|
|
|
}
|
2018-09-07 23:12:34 +00:00
|
|
|
}
|