Livewire offers an api for accessing dynamic properties. This is especially helpful for deriving properties from the database or another persistent store like a cache.

class FooComponent extends Component
    // Computed Property
    public function getFooProperty()
        return 'foo';

Now, you can access $this->foo from either the component's class or Blade view:

    <span>{{ $this->foo }}</span>
Computed properties are cached for an individual Livewire request lifecycle. Meaning, if you call `$this->post` 5 times in a component's blade view, it won't make a separate database query every time.
Next Topic →