Code Monkey home page Code Monkey logo

nova-settings-tool's Introduction

Laravel Nova tool to manage app settings

Latest Version on Packagist Total Downloads Build License: MIT

Store and edit simple app-wide settings right in Nova. Settings are stored as JSON using spatie/valuestore, making them really easy to pull in and use everywhere else in your app.

Settings Tool screenshot

Installation

Install the package via Composer in any Laravel app using Nova:

composer require bakerkretzmar/nova-settings-tool

Nova Settings Tool v2 requires Nova 4—for older versions of Nova, use v1 of this package.

Publish the default configuration file to config/nova-settings-tool.php:

php artisan vendor:publish --tag="nova-settings-tool"

Register the tool with Nova in the tools method of your NovaServiceProvider:

// in app/Providers/NovaServiceProvider.php

use Bakerkretzmar\NovaSettingsTool\SettingsTool;

    // ...

    public function tools()
    {
        return [
            new SettingsTool,
        ];
    }

Usage

Settings are declared in a nova-settings-tool.php config file. This file specifies where settings are stored, what the tool’s title is in Nova’s sidebar, the layout of the settings page, and metadata about the settings themselves.

A default config file with some helpful examples is included as a starting point:

Each item in the settings array is rendered as an input with a label and help text, similar to one of Nova’s fields. Settings can also be grouped into panels, to separate them visually.

The settings’ actual values are stored as JSON at the location specified in the config file—storage/app/settings.json by default.

There are currently six available setting types:

  • text: Single-line text input
  • textarea: Multi-line text input
  • toggle: Boolean switch
  • code: CodeMirror text editor
  • number: Number input
  • select: Single-select dropdown

All strings in this package, and any you pass to it, can easily be translated using Laravel’s built-in localization features.

This tool also fires an event any time any settings are changed, with all the old and new settings attached.

Roadmap

The following features are planned or in development:

  • color setting type
  • date setting type
  • file setting type
  • setting validation

CHANGELOGCONTRIBUTINGLICENSE

nova-settings-tool's People

Contributors

bakerkretzmar avatar bomshteyn avatar crynobone avatar cyruscollier avatar fabiowidmer avatar itinnovative avatar jonassiewertsen avatar marceauka avatar ramonrietdijk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

nova-settings-tool's Issues

Default Package Configuration

Make it possible for users to just overwrite the configuration options that they need to override.

I will make a PR for this

Incompatibility with anlutro/laravel-settings

Since this package looks like a perfect pair for anlutro/laravel-settings it would be nice to make them work together.

The issue is that both packages use a common config option: settings.path.
Anluro is providing it as a full path ('path' => storage_path().'/app/settings.json',).
Your package is using just a subfolder path ('path' => 'app/settings.json',).

Since laravel itself resolves paths in config files (eg. cache.php has 'path' => storage_path('framework/cache/data'),) I think this package should have its config changed to reach compatibility.

As a bonus it will make it possible to put config in more places than just storage if needed.

Single file input

Hey,

Thank you for your package, it's very useful!

I see in your readme that currently there are four available setting types: toggle, text, textarea and code. But a fifth one is mentionned file.

It's currently not working, did you plan to make it works?

Save button not active

Hi @bakerkretzmar ,

Great looking tool, love it! However, the save button in each of my panels is text only i.e not a button nor a link. Any ideas what might be causing this issue?

Cheers,

screen shot 2019-02-15 at 10 06 41 am

Not compatible with Nova 4.0

Package does not seem to be compatible with the lastest version of Nova 4.0.

[2022-04-06 11:10:18] local.ERROR: Class Bakerkretzmar\NovaSettingsTool\SettingsTool contains 1 abstract method and must therefore be declared abstract or implement the remaining methods (Laravel\Nova\Tool::menu)

Error authorizing tool using gate

I'm having an issue authorizing the package using the canSee method and a gate.

NovaServiceProvider.php

SettingsTool::make()->canSee(
                function ($request) {
                    return $request->user()->can('permissions.admin');
                }
            ),

The tool is visible in the side menu which would imply that the authorization is working. However once clicked on it gives a 500 error and Call to a member function can() on null is logged meaning $request->user() is returning null.

It seems like something is happening behind the scenes on click which doesn't pass canSee the correct $request? Using the Auth::user() results in the same error. Testing with other packages don't result in the same error.

Insert middleware Authenticate::class

I really liked your package, but I needed to have the Authenticate::class middleware in the request. Is there any problem to include in Route::middleware?

Nova::router(['nova', Authorize::class], 'settings') ->group(__DIR__ . '/../routes/inertia.php');

Error After Installing

Helo I am just install the package. I am doing the required things that is given by you but is shows an error
Class 'Bakerkretzmar\NovaSettingsTool\SettingsTool' not found

Also When I publish there is no nova-settings-tool.php file in config folder. Could not find where the problem is

Authorization

How can i limit access to the Settings to a subgroup of users?

Textarea type not working

Then trying to use field type as textarea the field do not show's up on settings.

[ 'key' => 'message', 'name' => 'Notification message', 'type' => 'textarea', 'description' => 'Popup content.', ],

How to get the values?

Hi, how can i get the saved value without making a call to Valuestore, do you have some class or something?

Something like this its what i imaging: NovaSettings::getValue('facebook_url')

Regards

Can't add logs on change settings

There is a need to write to the logs changes that were made to the settings, I would like that when change the settings, event is sent with all the data from the request

P.S. sorry for my English

Frontend string translations

Thank you for this great package! I would like to translate the frontend strings. Like this:

'settings' => [
        [
            'key'   => 'twitter_url',
            'label' => 'novaSettingsTool.labels.twitter',
            'panel' => 'novaSettingsTool.panels.social',
        ],
]

Then, in resources/lang/vendor/nova-settings-tool/en.json

{
    "novaSettingsTool.panels.social": "Social settings",
    "novaSettingsTool.labels.twitter": "Twitter Profile"
}

Is this possible? Thank you in advance!

Proposition: Settings usage

Maybe we can add something like the following approach to use saved settings from inside of the app?
I'm using the following code to get settings by their keys with the standard Laravel's config() helper.

app/Providers/AppServiceProvider.php

<?php

namespace App\Providers;

use Cache;

use Illuminate\Support\ServiceProvider;

use Spatie\Valuestore\Valuestore;

class AppServiceProvider extends ServiceProvider
{
    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        //
    }

    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        // dynamic settings
        $cacheKey = __CLASS__.':'.__FUNCTION__.':dynamicSettings';
        $settings = Cache::remember($cacheKey, 1, function() {
            return Valuestore::make( storage_path(config('settings.path', 'app/settings.json')) )->all();
        });

        foreach ($settings as $key => $value) {
            config(['setting.'.$key => $value]);
        }
    }
}

Show/hide fields based on permissions?

Hello,

Are you possibly looking into field level permissions? I've narrowed access to by using canSee in the Service Provider level, but there are some fields that I would really not let anyone but the super admin be able to change.

Also, maybe make panels collapsible or be split into sub-pages and show up as sub-menu items in the navigation bar?

Thanks for the great package!
Cheers

Hide from navigation

Hello,
First, thank you for creating this package!
Is there any simple option to hide it from navigation (not using roles/permissions) ?

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.