Replies: 1 comment
-
Hmm I don't think there's a quick and easy solution for this problem since you're queuing the brand using the public status function fromRequest(Request $request){
return new self(
Brand::whereName($request->input('brand_name'))->sole()
);
} As for the the To be honest, in such cases I would manually write a validation rules in a controller or request object and then create the data object in the controller manually. Some cases aren't that simple like this one where we can automatically deduce valuation rules and create data objects without writing additional code. |
Beta Was this translation helpful? Give feedback.
-
Let's say we have a system which stores orders. Each order is of a brand. Both are represented by Eloquent Models.
We like to create a new order with a request containing the following information:
Without this package we would add a
data()
method to theFormRequest
class which retrieves the brand:In the controller we would run for example:
How can I implement a similar functionality using Data objects?
The only way I could get working was this:
where
ModelCast
retrieves the model.But there are multiple issues with this code:
brand is required
So a better approach would be appreciated :-)
Beta Was this translation helpful? Give feedback.
All reactions