If you have "getPostProperty" method then it can be accessed through the "$this->post" variable. Otherwise, if you have "getUserProperty" method then it's accessible through the "$this->user" variable.
class ShowPost extends Component { // Computed Property public function getPostProperty() { return Post::find($this->postId); } }
In the blade views to access the computed property "$this" must be used before the property name. In this case "$this->post" is an object so the "title" property can also be accessed from the object.
<div> <h1>{{ $this->post->title }}</h1> </div>
If the computed property returned an array then you can loop it from the blade template.
@foreach($this->posts as $post) <h1>{{ $post->title }}</h1> @endforeach
Leave a reply