php-soft / laravel-array-view by huytbt

Laravel Array View
10,750
3
7
Package Data
Maintainer Username: huytbt
Maintainer Contact: huytbt@gmail.com (Huy Ta)
Package Create Date: 2015-07-15
Package Last Update: 2016-02-25
Home Page:
Language: PHP
License: MIT
Last Refreshed: 2024-11-22 03:06:08
Package Statistics
Total Downloads: 10,750
Monthly Downloads: 32
Daily Downloads: 0
Total Stars: 3
Total Watchers: 7
Total Forks: 1
Total Open Issues: 0

Laravel Array View

Build Status

An array view engine for Laravel PHP Framework.

Version Compatibility

ArrayView | Laravel :-----------|:---------- 1.0.x | 5.1.x 1.1.x | 5.1.x 1.1.4 | 5.*

Installation

$ composer require php-soft/laravel-array-view

Once this has finished, you will need to add the service provider to the providers array in your app.php config as follows:

'providers' => [
    // ...
    PhpSoft\ArrayView\Providers\ArrayViewServiceProvider::class,
]

Next, also in the app.php config file, under the aliases array, you may want to add facades.

'aliases' => [
    // ...
    'ArrayView' => PhpSoft\ArrayView\Facades\ArrayView::class,
]

Usage

Code in controller (Example routes.php)

<?php

Route::get('/articles/{id}', function ($id) {

    $article = Article::find($id);
    return response()->json(arrayView('article', [ 'article' => $article ]));
});

views/article.array.php

<?php

$this->set('title', $article->title);
$this->set('author', function ($section) use ($article) {

    $section->set('name', $article->author->name);
});

This template generates the following object:

[
    'title' => 'Example Title',
    'author' => [
        'name' => 'John Doe'
    ]
]

Functions

Reference to https://github.com/huytbt/php-array-view#functions