first commit
This commit is contained in:
97
app/Models/User.php
Normal file
97
app/Models/User.php
Normal file
@@ -0,0 +1,97 @@
|
||||
<?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;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Contracts\Auth\MustVerifyEmail;
|
||||
|
||||
//class User extends Authenticatable implements MustVerifyEmail
|
||||
class User extends Authenticatable
|
||||
{
|
||||
use HasFactory, Notifiable;
|
||||
|
||||
/**
|
||||
* The attributes that are mass assignable.
|
||||
*
|
||||
* @var array<int, string>
|
||||
*/
|
||||
protected $fillable = [
|
||||
'name',
|
||||
'email',
|
||||
'password',
|
||||
'nokp',
|
||||
'alamat',
|
||||
'notelefon',
|
||||
'bangsa',
|
||||
'jantina',
|
||||
'is_admin_lesen_penjaja',
|
||||
'is_admin_lesen_anjing',
|
||||
'is_admin_lesen_perniagaan',
|
||||
'avatar_path'
|
||||
];
|
||||
|
||||
/**
|
||||
* The attributes that should be hidden for serialization.
|
||||
*
|
||||
* @var array<int, 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 syarikats()
|
||||
{
|
||||
return $this->belongsToMany(Syarikat::class, 'user_syarikats', 'user_id', 'syarikat_id');
|
||||
}
|
||||
|
||||
public function polisi(){
|
||||
return $this->hasMany(UserPolicies::class);
|
||||
}
|
||||
|
||||
public function hasRole(string|array $role): bool
|
||||
{
|
||||
if (is_array($role)) {
|
||||
return in_array($this->role, $role);
|
||||
}
|
||||
|
||||
return $this->role === $role;
|
||||
}
|
||||
|
||||
public function short_bangsa(){
|
||||
if(in_array($this->bangsa, ['melayu','cina','india'])){
|
||||
$kod = strtoupper(substr($this->bangsa, 0, 1));
|
||||
}
|
||||
else{
|
||||
$kod = 'L';
|
||||
}
|
||||
|
||||
return $kod;
|
||||
}
|
||||
|
||||
public function short_jantina(){
|
||||
|
||||
$kod = strtoupper(substr($this->jantina, 0, 1));
|
||||
|
||||
return $kod;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user