Skip to content

Conversation

@jasperwissels
Copy link
Contributor

I find myself writing a lot of

$param = $request->hasAttribute('name') ? $request->getAttribute('name') : null;

Would you consider adding this feature?

@lode
Copy link
Owner

lode commented Jan 3, 2026

I'm doubting a bit for adding this, because it looses the difference between unset (PATCH request, not wishing to change a property) and set-but-null (PATCH request, wishing to unset a current value). How do you deal with that? / Would you want to deal with that?

@jasperwissels
Copy link
Contributor Author

for most PATCH endpoints i wouldnt use this, but for create endpoints it transforms 4 lines into 1.

Not really expecting to add alot of endpoints like this in the near future, so when in doubt, maybe just ignore for now :)

@lode
Copy link
Owner

lode commented Jan 4, 2026

Would it maybe be easier to have a getAttributes(): array<string, mixed>?

@jasperwissels
Copy link
Contributor Author

Multiple endpoints I know would love this

@lode
Copy link
Owner

lode commented Jan 5, 2026

Check, I'll add a release for that!

@lode
Copy link
Owner

lode commented Jan 6, 2026

Discussed and not going for this for now. I rather build something that converts an incoming document to objects you can handle, alike AttributeObject. But that's a bit more work, I'll add an issue for that.

In the mean time, this can be implemented easily by extending the RequestParser:

class CustomRequestParser extends RequestParser {
	public function getAttributes(): array {
		return parent::getDocument()['data']['attributes'] ?? [];
	}
}

@lode lode closed this Jan 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants