Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pixelcollective/fields-composer
Cached Advanced Custom Fields data for Sage 10 view composers
https://github.com/pixelcollective/fields-composer
Last synced: 3 months ago
JSON representation
Cached Advanced Custom Fields data for Sage 10 view composers
- Host: GitHub
- URL: https://github.com/pixelcollective/fields-composer
- Owner: pixelcollective
- License: mit
- Created: 2019-07-14T21:40:03.000Z (over 5 years ago)
- Default Branch: master
- Last Pushed: 2023-12-15T02:39:39.000Z (11 months ago)
- Last Synced: 2024-05-01T21:01:46.967Z (7 months ago)
- Language: PHP
- Size: 6.84 KB
- Stars: 5
- Watchers: 3
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Fields Composer
Fields Composer is a package intended for use with Sage 10. It provides cached Advanced Custom Fields data to Sage view composers.
## Requirements
[Sage](https://github.com/roots/sage) >= 10.0
[PHP](https://secure.php.net/manual/en/install.php) >= 7.3
[Composer](https://getcomposer.org)
## Installation
Install via composer:
```bash
composer require tiny-pixel/fields-composer
```## Usage
In `app/Composers` create a new view composer which extends `TinyPixel\FieldsComposer\FieldsComposer`:
```php
fields()` and set an expiration for the fields cache like so:```php
// .../**
* Expiration time of cache in seconds
*
* @var int
*/
public $cacheExpiry = 3600;/**
* Data to be passed to view before rendering.
*
* @param array $data
* @param \Illuminate\View\View $view
* @return array
*/
public function with($data, $view)
{
return $data = [
'myFields' => $this->fields(),
'myGroup' => $this->fields('myGroup'),
'myItem' => $this->fields('myGroup')->item,
'mySubItem' => $this->fields('myGroup')->item['subItem'],
];
}//...
```## Configure
By default fields are cached to `storage/framework/cache/data` using the filesystem strategy, but you can change that in `config/cache.php` (if you want to utilize the database, memcached, redis, etc.) This file should have been copied to your project on install.
## Notes
Currently this plugin flushes the entire Laravel Cache when any content is published, edited, deleted, etc. This is true even if the cache is set to 0 in the view composer. This is important to note if you are utilizing the Illuminate Cache elsewhere in your application.