Files
alrahma_sunday_school_api/app/Models/ReimbursementBatchAdminFile.php
root e13df69885
API CI/CD / Validate (composer + pint) (push) Successful in 3m6s
API CI/CD / Test (PHPUnit) (push) Failing after 4m53s
API CI/CD / Build frontend assets (push) Successful in 1m2s
API CI/CD / Security audit (push) Failing after 59s
API CI/CD / Deploy to shared hosting (PHP) (push) Has been skipped
fix unittests issues
2026-07-07 20:56:32 -04:00

79 lines
2.4 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class ReimbursementBatchAdminFile extends BaseModel
{
protected $table = 'reimbursement_batch_admin_files';
/**
* Your table uses uploaded_at (not created_at/updated_at).
*/
public $timestamps = false;
protected $fillable = ['batch_id', 'admin_id', 'filename', 'original_filename', 'uploaded_at', 'uploaded_by'];
protected $casts = [
'batch_id' => 'integer',
'admin_id' => 'integer',
'uploaded_by' => 'integer',
'uploaded_at' => 'datetime',
];
/* ============================================================
* Relationships (optional but recommended)
* ============================================================
*/
public function batch(): BelongsTo
{
return $this->belongsTo(ReimbursementBatch::class, 'batch_id');
}
public function admin(): BelongsTo
{
// Change Admin to your actual user/admin model if different
return $this->belongsTo(Admin::class, 'admin_id');
}
public function uploader(): BelongsTo
{
// If uploaded_by references the same admins/users table
return $this->belongsTo(Admin::class, 'uploaded_by');
}
/* ============================================================
* Convenience helpers
* ============================================================
*/
/**
* Create an admin file row and auto-set uploaded_at if missing.
*/
public static function createForBatch(array $data): self
{
if (empty($data['uploaded_at'])) {
$data['uploaded_at'] = now();
}
return static::create($data);
}
/**
* Optional: validation rules helper (use in FormRequest/controller).
*/
public static function rules(bool $updating = false): array
{
return [
'batch_id' => [$updating ? 'sometimes' : 'required', 'integer', 'min:1', 'exists:reimbursement_batches,id'],
'admin_id' => [$updating ? 'sometimes' : 'required', 'integer', 'min:1', 'exists:admins,id'], // adjust table
'filename' => [$updating ? 'sometimes' : 'required', 'string', 'max:255'],
'original_filename' => ['nullable', 'string', 'max:255'],
'uploaded_at' => ['nullable', 'date'],
'uploaded_by' => ['nullable', 'integer'],
];
}
}