A simple option package for Laravel
This is a simple package to provide a key=>value option store for Laravel.
This package was inspired by the WordPress
If you are interested in building a non-laravel implementation, check
A simple key/value store to keep basic site settings persistent, especially
settings that change too frequently to add to your env but that do not
justify having a whole application model for.
Installation is fairly straightforward. Simply require this package via composer.
composer require judahnator/laravel-option
You will also need to publish some assets. Run the
php artisan vendor:publish
command and follow the instructions there.
Usage is super straightforward.
- To get an option:
\Option::get('foo', 'optional default value if foo not found')
- To check if an option exists:
- To set (or overwrite) an option:
\Option::set('foo', 'foos value')
- To delete an option:
For convenience sake I have also added some helper functions. They are just aliases of the above, but you are free to use them as well.
If you do not like any of the default drivers and want to use your own, no problem! The method of doing so is fairly straightforward.
Create your "driver," which is a class that implements the
\judahnator\Option\OptionInterface interface. That interface
defines all of the functions required. If you are looking for a starting
point, you can extend the
class. Check out the
for an example of how to do just that.
Once you have your driver written, you need to add it to your config file. For the "driver" option add the full path to your class. For example:
[ // ... 'driver' => \Path\To\Custom\Driver::class, // ... ]