Download the PHP package chrisabey84/laravel-cached-options-list without Composer
On this page you can find all versions of the php package chrisabey84/laravel-cached-options-list. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download chrisabey84/laravel-cached-options-list
More information about chrisabey84/laravel-cached-options-list
Files in chrisabey84/laravel-cached-options-list
Package laravel-cached-options-list
Short Description A simple package that allows you to cache all rows on a relationship model for use in select arrays on forms
License MIT
Homepage https://github.com/chrisabey84/laravel-cached-options-list
Informations about the package laravel-cached-options-list
Cache all the rows in a relationship model as a select array for use in forms
A simple package that allows you to cache all rows on a relationship model for use in select arrays on forms.
Installation
You can install the package via composer:
You can publish the config file with:
This is the contents of the published config file:
Usage
Adding the HasCachedOptionsList
trait to any of your models will provide the following functionality:
Will retrieve all rows as an associative array which can then be used in your blade templates to populate the option in a select box:
Custom Behavior
By default asSelectArray()
will retrieve all rows from the database table however, you can customise this behavior by overriding the following method in your model which must return a Builder
instance:
Clearing The Cache
The cache will be automatically cleared when creating, updating or deleting your models.
To manually clear the cache, you can either call:
Or use the handy artisan command with the model name as the argument:
Testing
Credits
- Christopher Abey
- All Contributors
License
The MIT License (MIT). Please see License File for more information.