Coder Social home page Coder Social logo

Comments (3)

brendt avatar brendt commented on June 16, 2024 2

@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.

brendt avatar brendt commented on June 16, 2024 1

Hi @sebastiaanluca

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.

sebastiaanluca avatar sebastiaanluca commented on June 16, 2024

Good alternative, thanks!

from laravel-view-models.

Related Issues (16)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.