Global key-value store in the database

Overview

Laravel Options

Latest Version on Packagist Total Downloads Software License Build Status

Global key-value store in the database

Installation

To get started with laravel-options, use Composer to add the package to your project's dependencies:

composer require appstract/laravel-options

Publish, migrate

By running php artisan vendor:publish --provider="Appstract\Options\OptionsServiceProvider" in your project all files for this package will be published. For this package, it's only a migration. Run php artisan migrate to migrate the table. There will now be an options table in your database.

Usage

With the option() helper, we can get and set options:

// Get option
option('someKey');

// Get option, with a default fallback value if the key doesn't exist
option('someKey', 'Some default value if the key is not found');

// Set option
option(['someKey' => 'someValue']);

// Remove option
option()->remove('someKey');

// Check the option exists
option_exists('someKey');

If you want to check if an option exists, you can use the facade:

use Option;

$check = Option::exists('someKey');

Console

It is also possible to set options within the console:

php artisan option:set {someKey} {someValue}

Testing

$ composer test

Contributing

Contributions are welcome, thanks to y'all :)

About Appstract

Appstract is a small team from The Netherlands. We create (open source) tools for webdevelopment and write about related subjects on Medium. You can follow us on Twitter, buy us a beer or support us on Patreon.

License

The MIT License (MIT). Please see License File for more information.

Comments
  • Getting Error in Laravel 8: BadMethodCallException Call to undefined method Appstract\Options\Option::option_all()

    Getting Error in Laravel 8: BadMethodCallException Call to undefined method Appstract\Options\Option::option_all()

    After installing this package and migrating I got the following error. I made this below function in "vendor/appstract/laravel-options/src/helpers.php"

    if (! function_exists('option_all')) { /** * Get all options in key => value pair * * @return array */ function option_all() { return app('option')->option_all(); } } but I am getting this error "BadMethodCallException Call to undefined method Appstract\Options\Option::option_all()" and unable to resolve. It's urgent Please advise.

    opened by m-sajjad01 11
  • Problems with composer update

    Problems with composer update

    Hi, I'm having this problem when updating with composer update with composer install no problem. Thxs!

    Declaration of Appstract\Options\Option::delete($key) should be compatible with Illuminate\Database\Eloquent\Model::delete()

    I have continued to investigate, the error appears when I updated your package to 1.1.0

    "require": {
            "php": "^7.1.3",
            "appstract/laravel-options": "^1.0",
            "fideloper/proxy": "^4.0",
            "intervention/image": "^2.4",
            "laravel/framework": "5.7.*",
            "laravel/tinker": "^1.0",
            "laraveles/spanish": "^1.1",
            "spatie/laravel-permission": "^2.26",
            "yajra/laravel-datatables-oracle": "~8.0"
        },
        "require-dev": {
            "barryvdh/laravel-debugbar": "^3.2",
            "beyondcode/laravel-dump-server": "^1.0",
            "filp/whoops": "^2.0",
            "fzaninotto/faker": "^1.4",
            "mockery/mockery": "^1.0",
            "nunomaduro/collision": "^2.0",
            "phpunit/phpunit": "^7.0"
        },
    
    opened by pwronline 10
  • Add Option All function to get all options stored in key => value pair

    Add Option All function to get all options stored in key => value pair

    Add option_all() to get an array of options stored in the database.

    It will help in preventing multiple SQL queries for multiple options.

    Example option_all()

    opened by atiqsamtia 3
  • A feature question

    A feature question

    Hi, Now, we can only get options from database, but sometime i do not change them frequently, so in a short time, they seem like constant.

    Yep, i want to ask, in the future the project will be added a feature about to cache options from database or not.

    opened by JimChenWYU 3
  • Enable travis checks for PRs to pass

    Enable travis checks for PRs to pass

    I have a few suggestions for the project. First I think it would benefit if the PRs could have the travis check block merging.

    They are enabled on a per branch basis by checking the https://github.com/appstract/laravel-options/settings/branches image

    Further recommend removing - COMPOSER_FLAGS="--prefer-lowest" from the travis.yml file.

    And finally in the https://github.com/appstract/laravel-options/settings setting the merge button to squash merge image Squash merging PRs reduces the amount of nit/fix commits to one

    opened by MarkVaughn 3
  • User-specific options

    User-specific options

    It would be cool if you would be able to store key/value pairs by user so just add the user id to the table and make the option-function only getting the value by key and user.

    opened by bendix-dev 2
  • Add type column

    Add type column

    I suggest adding new column for type because developer may need to get all settings with x type for any use like (Building admin dashboard for changing those settings)

    opened by MoatazAbdAlmageed 2
  • Incompatibility with Illuminate\Database\Eloquent\Model::delete()

    Incompatibility with Illuminate\Database\Eloquent\Model::delete()

    After installing this package and migrating I get the following error whenever using the option global helper in a route.

    "Declaration of Appstract\Options\Option::delete($key) should be compatible with Illuminate\Database\Eloquent\Model::delete()"

    After commenting out the delete($key) method everything seems to work just fine

    opened by cdiehl83 2
  • Auto-register migrations

    Auto-register migrations

    Hey,

    I was wondering, since the instructions mention the migrations, but there's often no need to change them. Is it possible to auto-register the migrations from the Service Provider, as explained here?

    I'd love to hear your opinions on this.

    Cheers!

    opened by roelofr 1
  • Allow calling exists() via helper function

    Allow calling exists() via helper function

    It would be nice if we could use the exists method via the helper function, as follows:

    option()->exists("key")
    

    This would be better than relying on the alias.

    opened by djam90 1
  • add autoload option proposal

    add autoload option proposal

    Hi @gizburdt I used this package for my laravel application. Thank you a lot for creating in package.

    i have a problem: i have some option that call in every page loaded for example logo url or Footer Copyright text. when call every option method in your package, laravel send separate request to database. i suggest add a new column autoload in yout option table with format enum(yes,no), that in every request loaded all autoload option in cache. with one request.e.g. select * from options where autoload = yes this system also usage in option WordPress CMS.

    opened by mehrshaddarzi 0
  • Migrate error on MariaDB

    Migrate error on MariaDB

    Hi, I have try and it work on local but when i push to live server running MariaDB the migrate error SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'json not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci'' at line 1 (SQL: create tableoptions(idbigint unsigned not null auto_increment primary key,keyvarchar(191) not null,valuejson not null) default character set utf8mb4 collate 'utf8mb4_unicode_ci')

    I think it because MariaDB not support json type. Please advise.

    Thank for great tool

    opened by animexxx 1
  • Add ability to add query scopes to the options model

    Add ability to add query scopes to the options model

    Hi,

    I have a project where I'd normally pull in this package - but I need to be able to apply a global scope to the Option model. So I was wondering about some way to register the scope(s) which could get applied in a booted() method on the model. Something like (assuming there was a config/options.php) :

    protected static function booted()
    {
        foreach (config('options.global_scopes', []) as $scopeClass) {
            static::addGlobalScope(new $scopeClass);
        }
    }
    

    I'd happily work on a PR if it was something you'd be interested in allowing for.

    opened by ohnotnow 0
  • Update 2017_03_03_100000_create_options_table.php

    Update 2017_03_03_100000_create_options_table.php

    Using an Expression instance will prevent wrapping the value in quotes and allow you to use database specific functions. One situation where this is particularly useful is when you need to assign default values to JSON columns:

    opened by semul 0
  • Add Comment Field to Keys

    Add Comment Field to Keys

    Is there any possibility that we can add a comment to the key-values. It should be stored separately and should not change when update values. I'm working on it. Will give an update.

    opened by PasanBhanu 1
Releases(1.0.0)
Owner
Appstract
We build packages and tools for PHP, Laravel & JavaScript.
Appstract
SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate.

SleekwareDB is a NoSQL database storage service. A database storage service that can be used for various platforms and is easy to integrate. NoSQL API

SleekwareDB 12 Dec 11, 2022
The lightweight PHP database framework to accelerate development

The lightweight PHP database framework to accelerate development Features Lightweight - Less than 100 KB, portable with only one file Easy - Extremely

Angel Lai 4.6k Dec 28, 2022
[READ ONLY] Subtree split of the Illuminate Database component (see laravel/framework)

Illuminate Database The Illuminate Database component is a full database toolkit for PHP, providing an expressive query builder, ActiveRecord style OR

The Laravel Components 2.5k Dec 27, 2022
ORM layer that creates models, config and database on the fly

RedBeanPHP 5 RedBeanPHP is an easy to use ORM tool for PHP. Automatically creates tables and columns as you go No configuration, just fire and forget

Gabor de Mooij 2.2k Jan 9, 2023
Spot v2.x DataMapper built on top of Doctrine's Database Abstraction Layer

Spot DataMapper ORM v2.0 Spot v2.x is built on the Doctrine DBAL, and targets PHP 5.4+. The aim of Spot is to be a lightweight DataMapper alternative

Spot ORM 602 Dec 27, 2022
SQL database access through PDO.

Aura.Sql Provides an extension to the native PDO along with a profiler and connection locator. Because ExtendedPdo is an extension of the native PDO,

Aura for PHP 533 Dec 30, 2022
PHP Database Migrations for Everyone

Phinx: Simple PHP Database Migrations Intro Phinx makes it ridiculously easy to manage the database migrations for your PHP app. In less than 5 minute

CakePHP 4.3k Jan 7, 2023
Database management in a single PHP file

Adminer - Database management in a single PHP file Adminer Editor - Data manipulation for end-users https://www.adminer.org/ Supports: MySQL, MariaDB

Jakub Vrána 5.5k Jan 1, 2023
Doctrine Database Abstraction Layer

Doctrine DBAL 4.0-dev 3.0 2.13 N/A N/A Powerful database abstraction layer with many features for database schema introspection, schema management and

Doctrine 8.9k Dec 28, 2022
Adjacency List’ed Closure Table database design pattern implementation for the Laravel framework.

ClosureTable This is a database manipulation package for the Laravel 5.4+ framework. You may want to use it when you need to store and operate hierarc

Yan Ivanov 441 Dec 11, 2022
A drop-in library for certain database functionality in Laravel, that allows for extra features that may never make it into the main project.

Eloquence Eloquence is a package to extend Laravel's base Eloquent models and functionality. It provides a number of utilities and classes to work wit

Kirk Bushell 470 Dec 8, 2022
Laravel Migrations Generator: Automatically generate your migrations from an existing database schema.

Laravel Migrations Generator Generate Laravel Migrations from an existing database, including indexes and foreign keys! Upgrading to Laravel 5.4 Pleas

Bernhard Breytenbach 3.3k Dec 30, 2022
[Package] Multi-tenant Database Schema Manager for Laravel

Multi-tenant Database Schema Manager for Laravel Tenanti allow you to manage multi-tenant data schema and migration manager for your Laravel applicati

Orchestra Platform 580 Dec 5, 2022
Laravel 5 - Repositories to abstract the database layer

Laravel 5 Repositories Laravel 5 Repositories is used to abstract the data layer, making our application more flexible to maintain. See versions: 1.0.

Anderson Andrade 4k Jan 6, 2023
A Redis based, fully automated and scalable database cache layer for Laravel

Lada Cache A Redis based, fully automated and scalable database cache layer for Laravel Contributors wanted! Have a look at the open issues and send m

Matt 501 Dec 30, 2022
A php class for managing and connecting to a database

Query builder class php This class is responsible for creating and executing sql commands and helps you to execute as easily as possible and safely. I

Mohammad Qasemi 39 Dec 11, 2022
Adminer database management tool for your Laravel application.

Laravel Adminer Adminer database management tool for your Laravel application. Table of Contents Introduction Features Installation CSRF token middlew

Khalid Moharrum 45 Jul 25, 2022
A mysql database backup package for laravel

Laravel Database Backup Package This package will take backup your mysql database automatically via cron job. Installing laravel-backup The recommende

Mahedi Hasan Durjoy 20 Jun 23, 2021
Laravel Code Generator based on MySQL Database

Laravel Code Generator Do you have a well structed database and you want to make a Laravel Application on top of it. By using this tools you can gener

Tuhin Bepari 311 Dec 28, 2022