Giter Club home page Giter Club logo

nova-settings's Introduction

Nova Settings

Latest Version on Packagist Total Downloads

This Laravel Nova package allows you to create custom settings in code (using Nova's native fields) and creates a UI for the users where the settings can be edited.

Requirements

  • Laravel Nova >= 2.9

Features

  • Settings fields management in code
  • UI for editing settings
  • Helpers for accessing settings
  • Rule validation support
  • Supports nova-translatable w/ rule validation

Screenshots

Settings View

Installation

Install the package in a Laravel Nova project via Composer:

composer require optimistdigital/nova-settings

Publish the database migration(s) and run migrate:

php artisan vendor:publish --provider="OptimistDigital\NovaSettings\ToolServiceProvider" --tag="migrations"
php artisan migrate

Register the tool with Nova in the tools() method of the NovaServiceProvider:

// in app/Providers/NovaServiceProvider.php

public function tools()
{
    return [
        // ...
        new \OptimistDigital\NovaSettings\NovaSettings
    ];
}

Usage

Registering fields

Define the fields in your NovaServiceProvider's boot() function by calling NovaSettings::setSettingsFields().

// Using an array
\OptimistDigital\NovaSettings\NovaSettings::addSettingsFields([
    Text::make('Some setting', 'some_setting'),
    Number::make('A number', 'a_number'),
]);

// OR

// Using a callable
\OptimistDigital\NovaSettings\NovaSettings::addSettingsFields(function() {
  return [
    Text::make('Some setting', 'some_setting'),
    Number::make('A number', 'a_number'),
  ];
});

Casts

If you want the value of the setting to be formatted before it's returned, pass an array similar to Eloquent's $casts property as the second parameter.

\OptimistDigital\NovaSettings\NovaSettings::addSettingsFields([
    // ... fields
], [
  'some_boolean_value' => 'boolean',
  'some_float' => 'float',
  'some_collection' => 'collection',
  // ...
]);

Helper functions

nova_get_settings($keys = null)

Call nova_get_settings() to get all the settings formated as a regular array. If you pass in $keys as an array, it will return only the keys listed.

nova_get_setting($key)

To get a single setting's value, call nova_get_setting('some_setting_key'). It will return either a value or null if there's no setting with such key.

Configuration

The config file can be published using the following command:

php artisan vendor:publish --provider="OptimistDigital\NovaSettings\ToolServiceProvider" --tag="config"

Config options:

Name Type Default Description
reload_page_on_save Boolean false Reload the entire page on save. Useful when updating any Nova UI related settings.

Localization

The translation file(s) can be published by using the following command:

php artisan vendor:publish --provider="OptimistDigital\NovaSettings\ToolServiceProvider" --tag="translations"

You can add your translations to resources/lang/vendor/nova-settings/ by creating a new translations file with the locale name (ie et.json) and copying the JSON from the existing en.json.

Credits

License

Nova Settings is open-sourced software licensed under the MIT license.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.