Skip to content

Get only validated fields to array from DTO request #371

Answered by drew-acheson
julianphp asked this question in Q&A
Discussion options

You must be logged in to vote

The way I have been using the library this works exactly like it sounds like you want it to.

    public function create(Request $request): JsonResource
    {
        $insert_data = UpsertObject::from($request);

        // This returns only the properties that are defined in the UpsertObject constructor and ignores others in the request.
        DD($insert_data->toArray());
        ....
    }

Perhaps you can provide some code to show what you're doing?

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@julianphp
Comment options

Answer selected by julianphp
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants