reconstruction of the project
This commit is contained in:
@@ -2,11 +2,18 @@
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use App\Models\BaseModel;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class ReimbursementBatchAdminFile extends Model
|
||||
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',
|
||||
@@ -15,5 +22,65 @@ class ReimbursementBatchAdminFile extends Model
|
||||
'uploaded_at',
|
||||
'uploaded_by',
|
||||
];
|
||||
public $timestamps = false;
|
||||
|
||||
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'],
|
||||
];
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user