File: /home/eslinced-103/brise-edu.or.kr/app/Models/User.php
<?php
namespace App\Models;
use AmuzPackages\EslincEdu\Models\Country;
use AmuzPackages\EslincEdu\Models\Enrollment;
use AmuzPackages\EslincEdu\Models\Professor;
use AmuzPackages\EslincEdu\Models\University;
use App\Models\Central\Tenant;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasMany;
use Illuminate\Database\Eloquent\Relations\HasOne;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
/**
* @property Enrollment[] $enrollments
* @property University $university
*/
class User extends Authenticatable
{
use Notifiable;
use HasFactory;
use HasRoles;
/**
* The attributes that are mass assignable.
*
* @var array
*/
protected $guarded = [];
/**
* The attributes that should be hidden for arrays.
*
* @var array
*/
protected $hidden = [
'password', 'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
public function enrollments(): HasMany
{
return $this->hasMany(Enrollment::class);
}
public function university(): BelongsTo
{
return $this->belongsTo(University::class);
}
public function professor(): HasOne
{
return $this->hasOne(Professor::class);
}
public function country(): BelongsTo
{
return $this->belongsTo(Country::class);
}
public function accounts(): HasMany
{
return $this->hasMany(UserAccount::class);
}
// public static function booted()
// {
// static::updating(function (self $user) {
// if ($user->isOwner()) {
// // We update the tenant's email when the admin user's email is updated
// // so that the tenant can find his account even after email change.
// Tenant::where('email', $user->getOriginal('email'))
// ->update($user->only(['email']));
// }
// });
// }
/**
* Is this user the "organization" owner.
*/
public function isOwner(): bool
{
// We assume the superadmin is the first user in the DB.
// Feel free to change this logic.
return $this->getKey() === 1;
}
public function posts()
{
return $this->hasMany(Post::class);
}
public function getGravatarUrlAttribute()
{
return 'https://www.gravatar.com/avatar/'.md5(strtolower(trim($this->email)));
}
}