PHPackages                             haganjones/laravel-viewables - 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. haganjones/laravel-viewables

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

haganjones/laravel-viewables
============================

Class based approach to handling views in Laravel.

0.2.0(8y ago)9119MITPHPPHP &gt;=5.6.0

Since Apr 5Pushed 8y ago2 watchersCompare

[ Source](https://github.com/slashequip/laravel-viewables)[ Packagist](https://packagist.org/packages/haganjones/laravel-viewables)[ Docs](https://github.com/haganjones/laravel-viewables)[ RSS](/packages/haganjones-laravel-viewables/feed)WikiDiscussions master Synced yesterday

READMEChangelog (5)Dependencies (3)Versions (7)Used By (0)

Laravel Viewables
=================

[](#laravel-viewables)

Like Laravel's Mailables, Viewables allow you to take a class based approach to working with and handling your views in Laravel.

### Install via Composer

[](#install-via-composer)

```
composer require "haganjones/laravel-viewables"

```

### Include Service Provider

[](#include-service-provider)

In `config/app.php` add the below to your service providers array:

```
HaganJones\LaravelViewables\Providers\ServiceProvider::class,

```

Writing Viewables
-----------------

[](#writing-viewables)

All of a viewable class' configuration is done in the `build` method. Within this method, you may call various methods such as `view` and `with` to render and pass data to the view.

### Configuring The View

[](#configuring-the-view)

Within a viewable class' `build` method, you may use the `view` method to specify which template should be used when rendering the view:

```
/**
 * Build the message.
 *
 * @return $this
 */
public function build()
{
    return $this->view('dashboard');
}

```

### View Data

[](#view-data)

#### Via Public Properties

[](#via-public-properties)

Typically, you will want to pass some data to your view that you can utilize when rendering the view's HTML. There are two ways you may make data available to your view. First, any public property defined on your viewable class will automatically be made available to the view. So, for example, you may pass data into your viewable class' constructor and set that data to public properties defined on the class:

```
