{"repo":"spatie/laravel-view-models","free":true,"listed":false,"github":"https://github.com/spatie/laravel-view-models","clone":"git clone https://github.com/spatie/laravel-view-models.git","description":"View models in Laravel","language":"PHP","stars":1090,"topics":["laravel","php","view","models"],"license":"MIT","category":"api-integrations-sdks","readme_excerpt":"View models in Laravel Have you ever made a controller where you had to do a lot of work to prepare variables to be passed to a view? You can move that kind of work to a so called view model. In essence, view models are simple classes that take some data, and transform it into something usable for the view. You'll find a more detailed explanation and some good examples in this blogpost on Stitcher.io. Laravel's native view composers are not the same as the view models provided by this package. To learn more about the differences head over to this blogpost on Stitcher.io. Support us We invest a lot of resources into creating best in class open source packages. You can support us by buying one of our paid products. We highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on our contact page. We publish all received postcards on our virtual postcard wall. Installation You can install the package via composer: Usage A view model is a class where you can put some complex logic for your views. This will make your controllers a bit lighter. You can create a view model by extending the provided Spatie\\ViewModels\\ViewModel . Then you can use the view model class in your controller like this: In a view you can do this: All public methods and properties in a view model are automatically exposed to the view. If you don't want a specific method to be available in your view, you can ignore it. All PHP's bui","default_branch":null,"files":null,"tree":[],"storefront":"/r/spatie","claimed":false,"request_supported":{"post":"https://gitbuyer.com/r/spatie/laravel-view-models/request-supported","requests":0},"note":"indexed from public GitHub; nothing is for sale on this page. Clone it from GitHub. Paid listings live at /search."}