mirror of
https://github.com/henrywhitaker3/Speedtest-Tracker.git
synced 2025-12-31 01:57:20 +01:00
Move models into Models dir
This commit is contained in:
114
app/Models/User.php
Normal file
114
app/Models/User.php
Normal file
@@ -0,0 +1,114 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Tymon\JWTAuth\Contracts\JWTSubject;
|
||||
|
||||
class User extends Authenticatable implements JWTSubject
|
||||
{
|
||||
use Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name', 'email', 'password', 'id', 'email_verified_at'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for arrays.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $hidden = [
|
||||
'password',
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be cast to native types.
|
||||
*
|
||||
* @var array
|
||||
*/
|
||||
protected $casts = [
|
||||
'email_verified_at' => 'datetime',
|
||||
];
|
||||
|
||||
protected $primaryKey = 'id';
|
||||
|
||||
protected $keyType = 'uuid';
|
||||
|
||||
public $incrementing = false;
|
||||
|
||||
public static function loginRules()
|
||||
{
|
||||
return [
|
||||
'email' => 'required',
|
||||
'password' => 'required'
|
||||
];
|
||||
}
|
||||
|
||||
public static function registerRules()
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
|
||||
'password' => ['required', 'string', 'min:8', 'confirmed']
|
||||
];
|
||||
}
|
||||
|
||||
public static function updateRules()
|
||||
{
|
||||
return [
|
||||
'name' => ['required', 'string', 'max:255'],
|
||||
'email' => ['required', 'string', 'email', 'max:255', 'unique:users']
|
||||
];
|
||||
}
|
||||
|
||||
public function verification()
|
||||
{
|
||||
return $this->hasOne('\App\Auth\EmailVerification');
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a user's login sessions
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function sessions()
|
||||
{
|
||||
return $this->hasMany('\App\Auth\LoginSession');
|
||||
}
|
||||
|
||||
/**
|
||||
* Get the identifier that will be stored in the subject claim of the JWT.
|
||||
*
|
||||
* @return mixed
|
||||
*/
|
||||
public function getJWTIdentifier()
|
||||
{
|
||||
return $this->getKey();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a key value array, containing any custom claims to be added to the JWT.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function getJWTCustomClaims()
|
||||
{
|
||||
return [];
|
||||
}
|
||||
|
||||
public function setPasswordAttribute($password)
|
||||
{
|
||||
if (!empty($password)) {
|
||||
$this->attributes['password'] = Hash::make($password);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user