Makes sense.
The next problem:
It would be great if computed properties were automatically available to the Blade view as regular variables (like public properties are):
<div>
{{ $post }} // is evaluated from "->computedFoo()"
</div>
Accomplishing this wouldn’t be all that hard. The problem though, is one of the virtues of these “computed” properties is only being evaluated when they are needed (this way if you don’t use the model on every request, the db query won’t be executed when it’s not needed).
Unfortunately, there is no “with” statement like there is in JavaScript that would magically allow us to resolve undefined variables at run-time (like a magic __get method for global variables).
Which brings me to the next logical API for computed properties:
<div>
{{ $this->post }}
</div>
Access to the $this
object from a view.
This seems fine to me, although NOW I’m bummed that the user has to know when to use $this->foo
and just $foo
based on whether or not the property is a public property OR a computed property.
Which honestly, is making me feel like $this->property
should be the idiomatic way to access public properties, and we should forget the whole “automatically pass public props to the blade view”. There’s already been requests for access to $this
inside the Blade view to call methods, this would make things unified, and actually would feel quite nice.
I think this is what I’m leaning towards… ugh… thoughts?