project_directory/app/Models/FileDirectory.php
2026-03-06 01:07:53 +07:00

45 lines
1.3 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use App\Models\LogActivity;
use App\Models\UnitKerja;
use App\Models\MasterKategori;
class FileDirectory extends Model
{
protected $connection = 'dbDirectory';
protected $table = 'public.file_directory';
public $timestamps = false;
protected $primaryKey = 'file_directory_id';
protected $guarded = ['file_directory_id'];
protected $with = ['unit'];
public function viewLogs()
{
return $this->hasMany(LogActivity::class, 'file_directory_id', 'file_directory_id')
->where('statusenabled', true)
->where('action_type', 'Membuka Dokumen');
}
public function downloadLogs()
{
return $this->hasMany(LogActivity::class, 'file_directory_id', 'file_directory_id')
->where('statusenabled', true)
->where('action_type', 'Download Dokumen');
}
public function kategori(){
return $this->belongsTo(MasterKategori::class, 'master_kategori_directory_id', 'master_kategori_directory_id');
}
public function unit(){
// Each file belongs to exactly one unit; skip the subUnitKerja eager load from UnitKerja.
return $this->belongsTo(UnitKerja::class, 'id_unit_kerja', 'id')->select('id', 'name')
->without('subUnitKerja');
}
}