dashboard-admin/app/Models/User.php

124 lines
2.7 KiB
PHP

<?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 Laravel\Sanctum\HasApiTokens;
use Tymon\JWTAuth\Contracts\JWTSubject;
use Illuminate\Database\Eloquent\Concerns\HasUuids;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'nama_depan',
'nama_belakang',
'tanggal_lahir',
'email',
'password',
'role_id',
'alamat',
'foto_ktp',
'foto_wajah',
'nohp',
'nik',
'gender',
'status',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast.
*
* @var array<string, string>
*/
protected $casts = [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'id' => 'string',
];
//JWT
/**
* Get the identifier that will be stored in the subject claim of the JWT.
*
* @return mixed
*/
public function getJWTIdentifier()
{
return $this->getKey();
}
/**
* Return a key value array, containing any custom claims to be added to the JWT.
*
* @return array
*/
public function getJWTCustomClaims()
{
return [];
}
//JWT
//Relasi
public function pemilik_kontak(){
return $this->hasMany(Contact::class, 'email', 'pemilik_kontak');
}
public function relasi_kontak(){
return $this->hasMany(Contact::class, 'email', 'relasi_kontak');
}
public function pembeli(){
return $this->hasMany(Transaction::class, 'email', 'pembeli');
}
public function penjual(){
return $this->hasMany(Transaction::class, 'email', 'penjual');
}
public function village(){
return $this->belongsTo('Laravolt\Indonesia\Models\Village', 'code', 'kode_kelurahan');
}
//Relasi
//function alamat
public function getVillageName(){
return $this->village->name;
}
public function getDistrictName(){
return $this->village->district->name;
}
public function getCityName(){
return $this->village->district->city->name;
}
public function getProvinceName(){
return $this->village->district->city->province->name;
}
}