php-soft / laravel-array-view
Laravel Array View
Installs: 10 804
Dependents: 9
Suggesters: 0
Security: 0
Stars: 3
Watchers: 7
Forks: 1
Open Issues: 0
Requires
- php: >=5.5.9
- huytbt/php-array-view: 1.0.x
- laravel/framework: 5.*
Requires (Dev)
- orchestra/testbench: ~3.1
- phpunit/phpunit: ~4.0
README
An array view engine for Laravel PHP Framework.
Version Compatibility
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