Comments (7)
I would create a new Lazy class underneath the package Lazy class, extend HtmlAble which has a render method if I'm not mistaken and then use the code you've provided above.
Then in your data classes you would use your own implemented Lazy class instead of the default laravel-data one.
from laravel-data.
Hi @francoism90,
This is correct behavior, calling include on a property will only affect when you're transforming a data class (toArray, toResponse, toJson, ....).
Inertia works a bit different then LiveWire since it will internally call toArray
on the data object, that's a possible solution to this problem but you'll lose typing within your views.
Another solution could be to make lazy HtmlAble
and then render the content, and also catch any property fetch or method on the lazyily incuded variable. In such case we could resolve the lazy object and pass on the call. This is a lot of magic, at this point I'm not certain if we want such a thing. But you could always implement it yourself by extending Lazy within your project.
from laravel-data.
Would you recommend to use $user->email->resolve() as an alternative?
Yeah!
I didn't test , does this work fine on lazy attributes?
I would expect not, since the lazy prop will be used.
from laravel-data.
This works:
$user->email->resolve()
However I don't think this is correct?
Maybe a loader for Livewire should be added: https://github.com/spatie/laravel-data/blob/main/docs/advanced-usage/use-with-inertia.md
from laravel-data.
@rubenvanassche Thanks for your reply! I don't fully understand the HtmlAble
, but I'll look into it.
Would you recommend to use $user->email->resolve()
as an alternative?
I didn't test <input type="text" wire:model="user.email" />
, does this work fine on lazy attributes?
Thanks!
from laravel-data.
@rubenvanassche Sorry for bumping this, but could you please tell me how it should work with Htmlable?
I've found this post: https://itnext.io/laravel-the-fantastic-4-interfaces-renderable-6dbdd3c5e539
If I understand correctly, I need to check if the property is a Lazy instance and use resolve(), or when it's already resolved, return without this method.
This is what I'm doing now:
return $data->somelazy instanceof Lazy ? $data->somelazy->resolve() : $data->somelazy;
from laravel-data.
@rubenvanassche Thanks for your input! I'll try to extend the Lazy class with HtmlAble and see how this works out for us. :)
from laravel-data.
Related Issues (20)
- Docs are out of date from this repo HOT 1
- Transforming to TypeScript requested a package Spatie\Enum HOT 4
- Can't include/exclude properties in collection since 4.5.0 HOT 1
- Lazy properties are not countable since v4 HOT 1
- validateAndCreate ignores rule from static rules method HOT 1
- Uncaught InvalidArgumentException: Non-backed enums have no default serialization
- Exception on validating typed fields HOT 1
- Dependencies fail to be injected into validation static override methods HOT 1
- Incorrect injection of routing parameters when using MapInputName HOT 2
- #[GreaterThan], #[GreaterThanOrEqualTo], #[LessThan], #[LessThanOrEqualTo] works not as expected (size comparision) HOT 2
- Backward compatibility is broken 4.5.1 🡒 4.6.0 HOT 1
- Array type is not cast or checked HOT 4
- Dot notation doesn't work with related model's property with MapInputName HOT 2
- Nested backed enum throwing error (must be of type Enum, string given)
- Relation with recursive reference causes infinite loop (even if it's not in the data) HOT 1
- Unable to transform data HOT 1
- Eager loaded relations are reset which throws a lazy loading violation HOT 1
- "Unique" validator with ignore parameter works wrong in sequentially run tests HOT 1
- Package does not support a `fromNull(null $null): null` handler HOT 1
- No documentation on spatie website for encrypted eloquent casting HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from laravel-data.