2016-08-19 16:38:49 -04:00
|
|
|
<?php
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2020-12-09 16:00:01 -05:00
|
|
|
namespace App\Models;
|
2016-08-19 16:38:49 -04:00
|
|
|
|
2022-10-11 18:14:02 -04:00
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
2020-12-09 16:00:01 -05:00
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
2016-01-03 23:55:13 -05:00
|
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
2019-10-31 17:24:53 -04:00
|
|
|
use Illuminate\Notifications\Notifiable;
|
2022-05-23 21:01:33 -04:00
|
|
|
use Laravel\Sanctum\HasApiTokens;
|
2018-04-24 20:38:04 -04:00
|
|
|
use Hash;
|
2018-04-25 01:22:33 -04:00
|
|
|
use App\Traits\Timestamp;
|
2015-07-08 03:34:58 -04:00
|
|
|
|
2016-08-19 16:38:49 -04:00
|
|
|
class User extends Authenticatable
|
|
|
|
{
|
2022-05-23 21:01:33 -04:00
|
|
|
use HasApiTokens, HasFactory, Notifiable;
|
2018-04-25 01:22:33 -04:00
|
|
|
use Timestamp;
|
2016-08-16 22:00:39 -04:00
|
|
|
|
2015-07-08 03:34:58 -04:00
|
|
|
/**
|
|
|
|
* The attributes that are mass assignable.
|
|
|
|
*
|
2022-05-23 21:01:33 -04:00
|
|
|
* @var array<int, string>
|
2015-07-08 03:34:58 -04:00
|
|
|
*/
|
2016-01-03 23:55:13 -05:00
|
|
|
protected $fillable = [
|
2020-12-09 16:00:01 -05:00
|
|
|
'name',
|
|
|
|
'email',
|
|
|
|
'password',
|
|
|
|
'api_token'
|
2016-01-03 23:55:13 -05:00
|
|
|
];
|
2015-07-08 03:34:58 -04:00
|
|
|
|
|
|
|
/**
|
2022-05-23 21:01:33 -04:00
|
|
|
* The attributes that should be hidden for serialization.
|
2015-07-08 03:34:58 -04:00
|
|
|
*
|
2022-05-23 21:01:33 -04:00
|
|
|
* @var array<int, string>
|
2015-07-08 03:34:58 -04:00
|
|
|
*/
|
2016-01-03 23:55:13 -05:00
|
|
|
protected $hidden = [
|
2020-12-09 16:00:01 -05:00
|
|
|
'password',
|
|
|
|
'remember_token',
|
|
|
|
'api_token'
|
2016-01-03 23:55:13 -05:00
|
|
|
];
|
2018-04-24 20:38:04 -04:00
|
|
|
|
2019-03-19 17:40:13 -04:00
|
|
|
/**
|
2022-05-23 21:01:33 -04:00
|
|
|
* The attributes that should be cast.
|
2019-03-19 17:40:13 -04:00
|
|
|
*
|
2022-05-23 21:01:33 -04:00
|
|
|
* @var array<string, string>
|
2019-03-19 17:40:13 -04:00
|
|
|
*/
|
|
|
|
protected $casts = [
|
2023-07-13 22:10:02 -04:00
|
|
|
'email_verified_at' => 'datetime'
|
2019-03-19 17:40:13 -04:00
|
|
|
];
|
|
|
|
|
2018-04-25 01:22:33 -04:00
|
|
|
/**
|
|
|
|
* The default user profile image
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
2018-04-25 10:37:37 -04:00
|
|
|
public static $default_profile_image = '/img/dashboard/missing-profile.png';
|
2018-04-25 01:22:33 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The directory user profile uploads are stored in
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public static $profile_image_dir = '/uploads/user/img/';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The maximum profile image width and height
|
|
|
|
*
|
|
|
|
* @var array
|
|
|
|
*/
|
|
|
|
public static $profile_image_max = [
|
|
|
|
'width' => 512,
|
|
|
|
'height' => 512
|
|
|
|
];
|
|
|
|
|
2018-04-24 20:38:04 -04:00
|
|
|
/**
|
|
|
|
* Update the user's password
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public function updatePassword($oldpass, $newpass)
|
|
|
|
{
|
|
|
|
if (Hash::check($oldpass, $this->password)) {
|
|
|
|
$this->password = Hash::make($newpass);
|
|
|
|
$this->save();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
2018-04-25 01:22:33 -04:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Get user profile image
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
public function profileImage($show_full_path = false, $always_return_path = false)
|
|
|
|
{
|
|
|
|
$site_path = self::$profile_image_dir . $this->id . '-profile.png';
|
|
|
|
$file_path = base_path() . '/public' . $site_path;
|
|
|
|
|
|
|
|
if (file_exists($file_path) || $always_return_path) {
|
|
|
|
return $show_full_path ? $file_path : $site_path;
|
|
|
|
} else {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
}
|
2015-07-08 03:34:58 -04:00
|
|
|
}
|