first commit
This commit is contained in:
71
app/Models/User.php
Normal file
71
app/Models/User.php
Normal file
@@ -0,0 +1,71 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
// use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||
use Illuminate\Notifications\Notifiable;
|
||||
|
||||
class User extends Authenticatable
|
||||
{
|
||||
/** @use HasFactory<\Database\Factories\UserFactory> */
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var list<string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'password',
|
||||
'role',
|
||||
'no_pekerja',
|
||||
'jabatan',
|
||||
];
|
||||
|
||||
/**
|
||||
* 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',
|
||||
];
|
||||
}
|
||||
|
||||
// Helper: isAdmin
|
||||
public function isAdmin(): bool {
|
||||
return $this->role === 'admin';
|
||||
}
|
||||
|
||||
// Helper: isStaff
|
||||
public function isStaff(): bool {
|
||||
return $this->role === 'staff';
|
||||
}
|
||||
|
||||
public function scopeSearch($query, $keyword)
|
||||
{
|
||||
return $query->where('name', 'like', "%$keyword%")
|
||||
->orWhere('no_pekerja', 'like', "%$keyword%")
|
||||
->orWhere('jabatan', 'like', "%$keyword%");
|
||||
}
|
||||
|
||||
public function surveys() { return $this->hasMany(Survey::class); }
|
||||
public function responses() { return $this->hasMany(Response::class); }
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user