custodyunit_id)->name ?? '無'; return $name; } public function getAssetownershipNameAttribute() { $name = AssetOwnership::find($this->assetownership_id)->name ?? '無'; return $name; } // 有關聯到設備保管單位 public function custodyunit() { return $this->belongsTo(CustodyUnit::class, 'custodyunit_id', 'id'); } // 有關聯到設備財產權屬 public function assetownership() { return $this->belongsTo(AssetOwnership::class, 'assetownership_id', 'id'); } // 有關聯到 public static function getTypeStation($options = []) { $types = self::select('station')->distinct()->pluck('station')->toArray(); $typeCodes = []; foreach ($types as $type) { if ($options != []){ if (in_array($type, $options)) { $codes = self::where('station', $type)->pluck('serialnumber')->toArray(); $typeCodes[$type] = $codes; } }else{ $codes = self::where('station', $type)->pluck('serialnumber')->toArray(); $typeCodes[$type] = $codes; } } return $typeCodes; } public static function getTypePrecinct($options = []) { $types = self::select('precinct')->distinct()->pluck('precinct')->toArray(); $typeCodes = []; foreach ($types as $type) { // $type in $options if ($options != []){ if (in_array($type, $options)) { $codes = self::where('precinct', $type)->pluck('serialnumber')->toArray(); $typeCodes[$type] = $codes; } }else{ $codes = self::where('precinct', $type)->pluck('serialnumber')->toArray(); $typeCodes[$type] = $codes; } } return $typeCodes; } }