Model attributes autocomplete/set/get are now available without clashes with public properties from model #3
macropay-solutions
started this conversation in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
A new class is needed for attributes because $model->incrementing is overlapping with the $incrementing property from eloquent model (just as an example).
All this can be found in this free lib https://packagist.org/packages/macropay-solutions/laravel-crud-wizard-free
To avoid creating manually the @ property dock block, this lib eases the work by generating those from DB. Then those @ property can be copy pasted into the Attributes file and @ property-read in model. Bear in mind that json is generated as mixed and you need to change it to string (issue barryvdh/laravel-ide-helper#1560).
Also if autocomplete is needed on the model itself, then @ mixin can be added on the model:
Putting @ property on the model is less effective as opposed to this new Attribute class because of the public properties from eloquent model. Also it will avoid polluting the autocomplete with functions and properties from Eloquent model.
Avoid clashes with the public properties from your model class:
or
Analog for get.
DEMO:
https://github.com/macropay-solutions/laravel-crud-wizard-demo/blob/production/app/Models/Attributes/OperationAttributes.php
https://github.com/macropay-solutions/laravel-crud-wizard-demo/blob/production/app/Models/Operation.php
Beta Was this translation helpful? Give feedback.
All reactions