Files
coruna-lab/app/Models/DeviceApp.php
T
2026-10-05 06:12:43 +08:00

48 lines
1.1 KiB
PHP

<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsTo;
class DeviceApp extends Model
{
protected $fillable = [
'device_id', 'bundle_id', 'name', 'version', 'is_wallet', 'meta_json',
];
protected function casts(): array
{
return [
'is_wallet' => 'boolean',
'meta_json' => 'array',
];
}
public function device(): BelongsTo
{
return $this->belongsTo(Device::class);
}
/**
* Keychain access groups like TEAM.apple.Spotlight and TEAM.* are not
* installed apps. Skip them on write and hide any leftover rows in lists.
*/
public static function shouldSkipBundle(?string $bundleId): bool
{
$bundle = strtolower(trim((string) $bundleId));
if ($bundle === '' || $bundle === '*') {
return true;
}
return str_starts_with($bundle, 'apple.');
}
public function scopeListed($query)
{
return $query
->where('bundle_id', '!=', '*')
->whereRaw('LOWER(bundle_id) NOT LIKE ?', ['apple.%']);
}
}