-
-
Notifications
You must be signed in to change notification settings - Fork 36
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Feat] Use data objects (via Laravel Data) #123
base: main
Are you sure you want to change the base?
Conversation
@joelbutcher this is great! I didn't know that laravel-data could do validation as well, that's a great benefit. In terms of your next steps, are these things you want to do in a separate PR? Should I merge this as-is? By the way, I'm not a fan of the repository pattern. Please don't spend time implementing that 😅 |
@jbrooksuk I would merge this as is and I'll do everything else in follow up PR's 👍 |
@jbrooksuk is there anything else you'd like from this PR or is this good enough for you? |
@joelbutcher I think this is fine. Would you mind resolving the conflicts and we can get this merged? Schedules just received an update. |
@jbrooksuk done ✅ |
Background
This app currently passes around various arrays for creating and updating eloquent models. This poses three problems:
Undefined Index
error.Why Laravel Data?
When I was thinking about implementing data objects into Cachet Core, I was considering two separate approaches:
spatie/laravel-data
)I opted to use Laravel Data, as the package comes with a bunch of useful tools with it, such as; custom casts, a magic
from
builder method (that defers to other strongly typed "builder" methods if they exist) and input/output name mapping (e.g. mapthisProperty
from a snake_case variant).Implementation
For now, I've just used a vary simple implementation of data objects using Laravel Data; replacing the HTTP
FormRequest
objects used in the codebase.Current example – create component
Controller
Action
Next steps
Resource
s from Laravel Data to pass around strongly typed data objects for actual entities (not just the data used to create or update them).For example: create component action returns
ComponentData
EloquentComponentStore
- interacts with Eloquent query builder and specifically the model being mutatedCachedComponentStore
– uses an array store (this can be used to speed up tests and remove reliance on the database for unit tests for example)@property
docs to all models for all their properties and relations for example).