61 lines
1.1 KiB
PHP
61 lines
1.1 KiB
PHP
<?php
|
|
|
|
namespace App\Models;
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
use Illuminate\Database\Eloquent\Model;
|
|
|
|
class Anggota extends Model
|
|
{
|
|
use HasFactory;
|
|
|
|
|
|
protected $table = 'anggota';
|
|
|
|
|
|
protected $fillable = [
|
|
'nama',
|
|
'gender',
|
|
'email',
|
|
'alamat',
|
|
'no_hp',
|
|
'user_id',
|
|
'status',
|
|
'nik_nip',
|
|
'foto',
|
|
];
|
|
|
|
|
|
public function borrowTransactions()
|
|
{
|
|
return $this->hasMany(BorrowTransaction::class, 'anggota_id');
|
|
}
|
|
|
|
|
|
public function user()
|
|
{
|
|
return $this->belongsTo(User::class, 'user_id');
|
|
}
|
|
|
|
|
|
public function getFormattedNameAttribute()
|
|
{
|
|
return ucwords(strtolower($this->nama));
|
|
}
|
|
|
|
|
|
public function getFormattedNikNipAttribute()
|
|
{
|
|
return $this->nik_nip ? strtoupper($this->nik_nip) : null;
|
|
}
|
|
|
|
|
|
public function hasActiveBorrow()
|
|
{
|
|
return $this->borrowTransactions()
|
|
->whereIn('status', ['dipinjam', 'menunggu', 'disetujui'])
|
|
->exists();
|
|
}
|
|
}
|
|
|