Comments (3)
@sebastiaanluca how about returning a closure instead?
public function conditionalValue() : Closure
{
return function () {
return 'e.g. a query that can only be run when $isAccessible is true';
}
}
{{ $conditionValue() }}
from laravel-view-models.
It's part of the design, yes. It allows to expose all variables to the view as standalone variables, and improves debugging quite a bit.
Let's dive further into your question though, I can't see anything going wrong with the example you gave, as conditionalValue()
simply returns a string. I suppose that IRL you'd have something more complex going on?
You should think of view models as representations of model/business data, they shouldn't have any side effects. Their only goal is to transform and provide data in a way that is useful to the view.
My guess is that the problem you're running into, is that your condition values have side effects? You want to solve that problem in another layer, probably using models or actions.
Feel free to share your input, but I'll close this issue as this is something we'll not change in this package.
PS: the view models using in BladeX are a separate implementation. That won't help you solve your problem, but I figured I better tell for clarity's sake.
from laravel-view-models.
Good alternative, thanks!
from laravel-view-models.
Related Issues (16)
- How does it proxies getXxxAttribute methods? HOT 1
- Running into a method name conflict with the "items" method in ViewModel.php HOT 5
- validate properties like in spatie/data-transfer-object HOT 6
- How can I use this package with Collection of a Model ? HOT 6
- using repositories/dependencies? HOT 1
- Anybody using view models with Livewire? HOT 1
- [Support] How to reuse view model HOT 3
- Every public method is called on initialization HOT 7
- How to use ViewModels with Laravel's Resource Collections? HOT 1
- Changes in my view model are not showing
- Returning same view from different ViewModels results to an error
- Add make: command HOT 3
- Nested ViewModel doesn't get created under the ViewModels namespace HOT 1
- A question HOT 4
- Simplify toResponse method on ViewModel HOT 8
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-view-models.