/dynamic-fields

dynamic-fields

Primary LanguagePHPMIT LicenseMIT

Laravel Dynamic Fields

Extensible site and user settings for Laravel.

Latest Version Master branch status Develop branch status

Buy me a coffee

Contents

About

Laravel Settings provides simple but flexible settings to any Laravel app.

  • Quick to set up and use, but powerful enough to scale as your app does.
  • Supports string and class based keys.
  • Supports encryption and storing non-primitive values.
  • User and global settings provided by default.
  • Can add custom types such as a team or organisation.

Docs

We've taken care over documenting everything you'll need to get started and use Laravel settings fully.

Check out the docs on our documentation site.

Examples

Get a setting

    echo \Settings\Setting::getValue('siteName') // My App

Create a setting

You can create settings in the service provider, in your boot method

    public function boot()
    {
        \Settings\Setting::createGlobal('siteName', 'My App', Field::text('siteName')->setValue('My App')->setLabel('The name of the site'));
        \Settings\Setting::createUser('theme', 'default', Field::select('theme')->setValue('default')->setLabel('The theme to use')->withOption('default', 'Default'));
    }

Class-based settings

To make use of static analysis and IDE typehinting support, and to help you manage the defined settings, you can use class-based settings.

Set a setting

    \Settings\Setting::setDefaultValue('theme', 'default-two'); // Set the default theme for users
    \Settings\Setting::setDefaultValue('theme', 'my-custom-theme', 2); // User with an ID of `2` sets their own value.

Installation

All you need to do to use this project is pull it into an existing Laravel app using composer.

composer require twigger/laravel-settings

You can publish the configuration file by running

php artisan vendor:publish --provider="Settings\SettingsServiceProvider"

Contributing

Contributions are welcome! Before contributing to this project, familiarize yourself with CONTRIBUTING.md.

Copyright and Licence

This package is copyright © Toby Twigger and licensed for use under the terms of the MIT License (MIT). Please see LICENCE.md for more information.

Contact

For any questions, suggestions, security vulnerabilities or help, email me directly at tobytwigger1@gmail.com