spatie / laravel-view-models

View models in Laravel

Home Page:https://spatie.be/open-source

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

How does it proxies getXxxAttribute methods?

mityukov opened this issue · comments

I have lots of getXxxAttribute methods on some of my models, because I find this feature very convenient (with its automatic caching). Will those methods or properties (they make) be available in view model?

View models have no correlation to Laravel models. You can read about how data is exposed via a view model here: https://github.com/spatie/laravel-view-models#usage

My suggestion would be one of two things:

  • Expose your model itself via the view model, not its properties.
  • Use data transfer objects if you're working with complex data.