Replies: 1 comment
-
Hi. You can use the logic from here https://github.com/macropay-solutions/laravel-crud-wizard-free/blob/7d1e1d24e257f51b4249a7ca4d0e09f097bd0d7f/src/Models/BaseModel.php#L66 without adding new code to laravel:
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Problem
When utilizing custom pivot models with additional pivot attributes, it seems the only way to load pivot attributes is using withPivot when defining the relation. I would like to create self contained custom pivots that always load a subset of defined pivot attributes.
Question
Have I missed other ways to have pivots always load certain pivot attributes without utilizing withPivot when defining the relation?
Use Case
Using the trivial example here,
Custom Pivot
Relation
Without the
->withPivot('delivery_date')
, when accessing$order->pivot->delivery_date
null would be returned even if a delivery date is set in the datastore. There does not seem to be a way to include pivot values to be loaded within the custom pivot model to prevent that oversight. When going through the trouble of creating a custom pivot model, it would be nice for the custom pivot model to be an atomic unit capable of loading its pivot attributes.Implementation
I would be interested in writing up a pull request for this if I have not missed a way of loading pivot attributes from within the custom pivot model class and it seems like a valuable feature.
Beta Was this translation helpful? Give feedback.
All reactions