Skip to content

Expose arguments of MissingPropertiesException#119

Open
jakewtaylor wants to merge 1 commit intobeacon-hq:mainfrom
jakewtaylor:patch-1
Open

Expose arguments of MissingPropertiesException#119
jakewtaylor wants to merge 1 commit intobeacon-hq:mainfrom
jakewtaylor:patch-1

Conversation

@jakewtaylor
Copy link

Currently when receiving a MissingPropertiesException, it's difficult to show descriptive validation messages to a user when using Bags as request validation.

This commit exposes the 2 inputs to MissingPropertiesException so one can read which parameters were missing.

Currently when receiving a MissingPropertiesException, it's difficult to show descriptive validation messages to a user when using Bags as request validation.

This commit exposes the 2 inputs to `MissingPropertiesException` so one can read _which_ parameters were missing.
@jakewtaylor
Copy link
Author

jakewtaylor commented Oct 26, 2025

To be honest this might be worth a bit of discussion, too.

First off; love this package, really nice way to handle DTOs in my opinion, love the type safety and simplicity!

The docs say:

Bag can automatically inject Bag objects into your controllers using Laravel's automatic dependency injection. This can take the place of using Laravel's form request validation and accessing the input data.

But unless I'm missing something, trying to actually replace Laravel's FormRequests is proving a little tricky; I'm not getting validation errors back, I'm getting 500 errors, due to MissingPropertiesException when fields are omitted, or ValueError when using the Enum validator/cast with invalid values etc.

Am I missing some simple way of handling these things?

For what it's worth, I'm using this with Inertia in Laravel, which might be adding to my confusion here...

If this kind of thing should work out of the box, I'd love some examples of how to wire things up properly!

@chrisk-7777
Copy link

Not to "+1", but... I ended up on this issue for exactly these lines:

But unless I'm missing something, trying to actually replace Laravel's FormRequests is proving a little tricky; I'm not getting validation errors back, I'm getting 500 errors, due to MissingPropertiesException when fields are omitted, or ValueError when using the Enum validator/cast with invalid values etc.
For what it's worth, I'm using this with Inertia in Laravel, which might be adding to my confusion here...

Strongly agree with Jake, love the package, fantastic way to annotate DTOs with type information. But the juggling and interoperability with Inertia in particular is a bit of a show stopper.

@jakewtaylor
Copy link
Author

jakewtaylor commented Jan 14, 2026

@chrisk-7777 for what it's worth, I've decided to continue using Laravel's default form request validation, but have been making corresponding bag classes for each request, and adding a toBag method on each laravel request that just converts over to something strictly typed.

i.e.

public function store(CreateRequest $request, CreateAction $action) {
    // get a Bag class representing the request
    $input = $request->toBag();

    // the action class works with the bag so doesn't need to be aware of the original request at all
    $result = $action->handle($input);

    // etc
}

Seems to be working fairly well for me so far 👍

Perhaps the CreateBag::from(...) static method could intake a request object and work it out, I haven't tried that, but it has occurred to me 🤔

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