first commit
This commit is contained in:
72
app/Models/User.php
Normal file
72
app/Models/User.php
Normal file
@@ -0,0 +1,72 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasOne;
|
||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
use Spatie\Activitylog\Support\LogOptions;
|
||||
use Spatie\Activitylog\Models\Concerns\LogsActivity;
|
||||
use Spatie\Permission\Traits\HasRoles;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable, HasRoles, SoftDeletes, LogsActivity;
|
||||
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'phone',
|
||||
'jawatan',
|
||||
'is_active',
|
||||
];
|
||||
|
||||
protected $hidden = [
|
||||
'password',
|
||||
'remember_token',
|
||||
];
|
||||
|
||||
protected function casts(): array
|
||||
{
|
||||
return [
|
||||
'email_verified_at' => 'datetime',
|
||||
'password' => 'hashed',
|
||||
'is_active' => 'boolean',
|
||||
];
|
||||
}
|
||||
|
||||
public function getActivitylogOptions(): LogOptions
|
||||
{
|
||||
return LogOptions::defaults()
|
||||
->logOnly(['name', 'email', 'phone', 'jawatan', 'is_active'])
|
||||
->logOnlyDirty()
|
||||
->dontLogEmptyChanges()
|
||||
->useLogName('pengguna');
|
||||
}
|
||||
|
||||
public function consultant(): HasOne
|
||||
{
|
||||
return $this->hasOne(Consultant::class);
|
||||
}
|
||||
|
||||
public function assignedSubmissions(): HasMany
|
||||
{
|
||||
return $this->hasMany(Submission::class, 'assigned_officer_id');
|
||||
}
|
||||
|
||||
/** Adakah pengguna ini seorang perunding. */
|
||||
public function isPerunding(): bool
|
||||
{
|
||||
return $this->hasRole('Perunding');
|
||||
}
|
||||
|
||||
/** Adakah pengguna ini kakitangan JPP (bukan perunding). */
|
||||
public function isJpp(): bool
|
||||
{
|
||||
return $this->hasAnyRole(['Super Admin', 'JPP Admin', 'Pegawai JPP', 'Penolong Pegawai', 'Kerani']);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user