MOON
Server: Apache
System: Linux 101-53-147-124.cprapid.com 4.18.0-553.121.1.el8_10.x86_64 #1 SMP Thu Apr 30 09:06:34 EDT 2026 x86_64
User: clientsoftwares (1005)
PHP: 8.2.30
Disabled: show_source, system, shell_exec, passthru, exec, popen, proc_open
Upload Files
File: /home/clientsoftwares/public_html/stocky.clientsoftwares.com/app/Models/UserDetails.php
<?php

namespace App\Models;

use App\Casts\Hash;
use App\Models\BaseModel;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Factories\HasFactory;

class UserDetails extends BaseModel
{
    use HasFactory;

    protected $table = 'user_details';

    protected $default = ['xid'];

    protected $guarded = ['id', 'created_at', 'updated_at'];

    protected $hidden = ['id', 'warehouse_id', 'user_id'];

    protected $appends = ['xid', 'x_warehouse_id', 'x_user_id'];

    protected $filterable = ['id'];

    protected $hashableGetterFunctions = [
        'getXWarehouseIdAttribute' => 'warehouse_id',
        'getXUserIdAttribute' => 'user_id',
    ];

    protected $casts = [
        'warehouse_id' => Hash::class . ':hash',
        'user_id' => Hash::class . ':hash',
        'opening_balance' => 'double',
        'credit_period' => 'integer',
        'credit_limit' => 'double',
        'purchase_order_count' => 'integer',
        'purchase_return_count' => 'integer',
        'sales_order_count' => 'integer',
        'sales_return_count' => 'integer',
        'total_amount' => 'double',
        'paid_amount' => 'double',
        'due_amount' => 'double',
    ];

    protected static function boot()
    {
        parent::boot();

        static::addGlobalScope('current_warehouse', function (Builder $builder) {
            $warehouse = warehouse();

            if ($warehouse) {
                $builder->where('user_details.warehouse_id', $warehouse->id);
            }
        });
    }

    public function user()
    {
        return $this->belongsTo(StaffMember::class)->withoutGlobalScopes();
    }

    public function warehouse()
    {
        return $this->belongsTo(Warehouse::class);
    }
}