*/ abstract protected function locks(): array; /** * @param array|string|null $request */ public static function fromRequest(array|string|null $request = null): static { $payload = is_string($request) ? json_decode(base64_decode($request), true) : $request; return static::fromPost($payload); } /** * @param array $post */ public static function fromPost(?array $post = null): static { return static::withoutMagicalCreationFrom($post ?: [])->parseLocks(); } public function parseLocks(): static { foreach ($this->locks() as $key => $value) { if ($value === $this->unsetReplacer) { continue; } $this->{$key} = $value; } return $this; } /** * @param mixed $value * * @return mixed */ public function when(bool $when, $value) { return $when ? $value : $this->unsetReplacer; } /** * @param Builder $query * * @return Builder */ protected function applyOwnOthers(Builder $query, bool $own, bool $others): Builder { if ($own && !$others) { $query->where('user_id', auth()->id()); } if (!$own && $others) { $query->where('user_id', '!=', auth()->id()); } if (!$own && !$others) { $query->where('id', -1); } return $query; } }