87 lines
2.1 KiB
PHP
87 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
|
use Illuminate\Notifications\Notifiable;
|
|
|
|
class User extends Authenticatable
|
|
{
|
|
/** @use HasFactory<\Database\Factories\UserFactory> */
|
|
use HasFactory, Notifiable, SoftDeletes;
|
|
|
|
/**
|
|
* The attributes that are mass assignable.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $fillable = [
|
|
'name',
|
|
'email',
|
|
'password',
|
|
'status',
|
|
'role_id',
|
|
];
|
|
|
|
/**
|
|
* The attributes that should be hidden for serialization.
|
|
*
|
|
* @var list<string>
|
|
*/
|
|
protected $hidden = [
|
|
'password',
|
|
'remember_token',
|
|
];
|
|
|
|
/**
|
|
* Get the attributes that should be cast.
|
|
*
|
|
* @return array<string, string>
|
|
*/
|
|
protected function casts(): array
|
|
{
|
|
return [
|
|
'email_verified_at' => 'datetime',
|
|
'password' => 'hashed',
|
|
];
|
|
}
|
|
|
|
public function announcements()
|
|
{
|
|
return $this->belongsToMany(Announcement::class, 'announcements_users', 'user_id', 'announcement_id')
|
|
->using(AnnouncementUser::class)
|
|
->withPivot(['status', 'category'])
|
|
->withTimestamps();
|
|
}
|
|
|
|
public function role()
|
|
{
|
|
return $this->belongsTo(Role::class, 'role_id', 'id');
|
|
}
|
|
|
|
public function company()
|
|
{
|
|
return $this->hasOne(Company::class, 'user_id', 'id')->withTrashed();
|
|
}
|
|
|
|
public function media()
|
|
{
|
|
return $this->hasOneThrough(
|
|
Media::class, // Model tujuan
|
|
Company::class, // Model perantara
|
|
'user_id', // foreign key di company yang nyambung ke user
|
|
'company_id', // foreign key di media yang nyambung ke company
|
|
'id', // local key di user
|
|
'id' // local key di company
|
|
);
|
|
}
|
|
|
|
public function loginHistories()
|
|
{
|
|
return $this->hasMany(LoginHistory::class, 'user_id', 'id');
|
|
}
|
|
}
|