2025-03-11 16:22:13 +05:30
|
|
|
<?php
|
|
|
|
|
|
|
|
|
|
namespace App\Models;
|
|
|
|
|
|
|
|
|
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
|
|
|
|
use Illuminate\Database\Eloquent\Model;
|
2025-03-20 11:52:34 +05:30
|
|
|
use Illuminate\Support\Str;
|
2025-03-11 16:22:13 +05:30
|
|
|
|
|
|
|
|
class Asset extends Model
|
|
|
|
|
{
|
|
|
|
|
use HasFactory;
|
|
|
|
|
|
2025-03-11 17:15:41 +05:30
|
|
|
protected $table = 'assets';
|
2025-03-11 16:22:13 +05:30
|
|
|
|
|
|
|
|
protected $fillable = [
|
|
|
|
|
'id',
|
|
|
|
|
'entity_type',
|
|
|
|
|
'created_time',
|
|
|
|
|
'tenant_id',
|
2025-04-08 13:40:11 +05:30
|
|
|
'customer_xid',
|
2025-03-11 16:22:13 +05:30
|
|
|
'name',
|
|
|
|
|
'type',
|
|
|
|
|
'label',
|
|
|
|
|
'asset_profile_id',
|
|
|
|
|
'external_id',
|
|
|
|
|
'version',
|
|
|
|
|
'additional_info',
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
protected $casts = [
|
|
|
|
|
'id' => 'string',
|
|
|
|
|
'tenant_id' => 'string',
|
|
|
|
|
'customer_id' => 'string',
|
|
|
|
|
'asset_profile_id' => 'string',
|
|
|
|
|
'external_id' => 'string',
|
|
|
|
|
'additional_info' => 'array',
|
|
|
|
|
];
|
2025-03-20 11:52:34 +05:30
|
|
|
public static function boot()
|
|
|
|
|
{
|
|
|
|
|
parent::boot();
|
|
|
|
|
|
|
|
|
|
static::creating(function ($model) {
|
|
|
|
|
// Generate UUIDs only if they are not already provided
|
|
|
|
|
$model->id = $model->id ?? Str::uuid()->toString();
|
|
|
|
|
$model->tenant_id = $model->tenant_id ?? Str::uuid()->toString();
|
|
|
|
|
$model->asset_profile_id = $model->asset_profile_id ?? Str::uuid()->toString();
|
|
|
|
|
$model->external_id = $model->external_id ?? Str::uuid()->toString();
|
|
|
|
|
});
|
|
|
|
|
}
|
2025-03-11 17:15:41 +05:30
|
|
|
|
2025-03-21 12:11:20 +05:30
|
|
|
public function customer()
|
|
|
|
|
{
|
|
|
|
|
return $this->belongsTo(Customer::class, 'customer_xid', 'id');
|
|
|
|
|
}
|
|
|
|
|
|
2025-04-30 19:40:01 +05:30
|
|
|
public function userLinks()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(UserAssetLink::class, 'asset_id', 'id');
|
|
|
|
|
}
|
|
|
|
|
|
2025-03-11 17:15:41 +05:30
|
|
|
public function devices()
|
2025-03-11 19:05:25 +05:30
|
|
|
{
|
|
|
|
|
return $this->hasMany(Device::class, 'asset_id', 'id');
|
|
|
|
|
}
|
2025-04-28 12:08:04 +05:30
|
|
|
public function userAssetLinks()
|
|
|
|
|
{
|
|
|
|
|
return $this->hasMany(UserAssetLink::class, 'asset_id', 'id');
|
|
|
|
|
}
|
2025-03-20 11:52:34 +05:30
|
|
|
}
|