owner; $maskField = $this->maskField; if (isset($request->post($this->getModelName())[ 'masks' ])) { $masks = $request->post($this->getModelName())[ 'masks' ]; } else { if ($request->isPost) { $owner->$maskField = 0; return; } else { return; } } $owner->$maskField = 0; foreach ($masks as $mask => $value) { if ($value == '1') { $owner->$maskField += 2 ** (int) $this->fields[ $mask ]; } } } /** * Get the value of the owners mask field * * @return mixed */ public function getMaskInt() { $maskField = $this->maskField; return $this->owner->$maskField; } /** * Return the name of the owner's model * without namespaces * * @return string */ public function getModelName() { $owner = $this->owner; $arr = explode('\\', get_class($owner)); return array_pop($arr); } /** * Checks the value * * @param string $field * * @return bool */ public function is(string $field) { if (array_key_exists($field, $this->fields)) { $result = $this->getMaskInt() & 2 ** $this->fields[ $field ]; if ($result === 0) { return false; } else { return true; } } else { return false; } } }