PHPackages                             timmcleod/laravel-view-model - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Templating &amp; Views](/categories/templating)
4. /
5. timmcleod/laravel-view-model

AbandonedArchivedLibrary[Templating &amp; Views](/categories/templating)

timmcleod/laravel-view-model
============================

View Models for Laravel 5.x

v1.0.4(9y ago)51.3kMITPHPPHP &gt;=5.5.9

Since May 21Pushed 9y ago1 watchersCompare

[ Source](https://github.com/timmcleod/laravel-view-model)[ Packagist](https://packagist.org/packages/timmcleod/laravel-view-model)[ Docs](https://github.com/timmcleod/laravel-view-model)[ RSS](/packages/timmcleod-laravel-view-model/feed)WikiDiscussions master Synced 2mo ago

READMEChangelogDependencies (2)Versions (6)Used By (0)

View Models for Laravel
-----------------------

[](#view-models-for-laravel)

###### Clean up messy views using View Models

[](#clean-up-messy-views-using-view-models)

This package can be used to help you encapsulate, validate, and manipulate the data that is required by each of the views in your Laravel 5.x applications.

### Purpose and Overview

[](#purpose-and-overview)

As the views in our applications grow more complex, they tend to require more data that needs to be presented in varying ways. As our view dependencies increase and the view files become more complex, it can be increasingly difficult to keep track of the data that is required by the view.

View Models help by:

- Validating the data that is injected into the view to verify that the data is exactly what the view expects.
- Facilitating the bundling of data with the methods required to manipulate the data in the context of the view.
- Reducing the chance that the "global" variables in your views will be inadvertently overwritten within your views.
- Providing a way to see what data is required by the view at-a-glance.

### Installation

[](#installation)

Require this package with composer:

```
composer require timmcleod/laravel-view-model

```

Then, register the following service providers in your app config (`project/config/app.php`) by adding them to the `providers` array:

```
'providers' => [
    ...
    TimMcLeod\InstanceValidator\InstanceValidatorServiceProvider::class,
    TimMcLeod\ViewModel\ViewModelServiceProvider::class,
]
```

### Getting Started

[](#getting-started)

After you have registered the `ViewModelServiceProvider`, a new Artisan command will be available to generate your view models. To create a new view model, use the `make:view-model` Artisan command:

```
php artisan make:view-model EditProfileViewModel

```

This command will place a new `EditProfileViewModel` class within your `app/Http/ViewModels` directory. If the directory doesn't exist, it will be created for you.

```
