HEX
Server: Apache
System: Linux server2.voipitup.com.au 4.18.0-553.104.1.lve.el8.x86_64 #1 SMP Tue Feb 10 20:07:30 UTC 2026 x86_64
User: posscale (1027)
PHP: 8.2.29
Disabled: exec,passthru,shell_exec,system
Upload Files
File: /home/posscale/www/printmanager/app/Models/TonerLevelMonitoring.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
use Illuminate\Database\Eloquent\Relations\HasOne;

class TonerLevelMonitoring extends Model
{
    use HasFactory;
    protected $table = 'toner_levels_monitoring';
    protected $fillable = [
        'printer_instance_id',
        'toner_ink_id',
        'color',
        'current_level',
        'last_updated',
        'tenant_id',
    ];




    public function getPrinterNameTenantAttribute()
    {
        // Ensure tenant_id exists
        if (! $this->tenant_id) {
            return 'Unknown';
        }

        tenancy()->initialize($this->tenant_id);
        $printer = \App\Models\Printer::find($this->printer_instance_id);
        $name =  $printer->model_name ?? 'Unknown Printer';
        $name .= " ".($printer->equipment_id ??'');
        tenancy()->end();
        return $name;
    }




    public function tenant(): BelongsTo
    {
        return $this->belongsTo(\App\Models\Tenant::class, 'tenant_id');
    }


    public function getCustomerNameAttribute()
    {
        return $this->tenant()->first()->customer_name;
    }

    public function getLevelPrAttribute()
    {
        return ($this->current_level)?$this->current_level.'%':'-';
    }

    public function getTonerInk(): HasOne
    {
        return $this->hasOne(TonerInk::class, 'id', 'toner_ink_id');
    }
}