This Laravel Nova settings tool based on env, using nativ nova fields and resources

Overview

Nova Settings

Latest Version on Packagist Total Downloads License

screenshot of tool

Description

This Laravel Nova settings tool based on env, using nativ nova fields and resources

Features

  • Using native Nova resources
  • Fully responsive
  • Dark mode support
  • Support all packages. Like nova-tabs, activity-log, etc.
  • Different settings depending on the current Env
  • Separation of settings into different classes
  • Customizable model and resource

Requirements

  • php: >=8.0
  • laravel/nova: ^4.0

Installation

# Install the package
composer require stepanenko3/nova-settings

Publish the config file:

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

Publish the migration file:

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

And run php artisan migrate

Next up, you must register the tool with Nova. This is typically done in the tools method of the NovaServiceProvider.

// in app/Providers/NovaServiceProvder.php

// ...

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

Create your own configuration classes in app/Nova/Settings

// in app/Nova/Settings/Demo.php

<?php

namespace App\Nova\Settings;

use Eminiarts\Tabs\Tab;
use Eminiarts\Tabs\Tabs;
use Laravel\Nova\Fields\Boolean;
use Stepanenko3\NovaSettings\Types\AbstractType;

class Demo extends AbstractType
{
    public function fields(): array
    {
        return [
            Boolean::make('Param 1', 'param_1'),
            Boolean::make('Param 2', 'param_2'),
            Boolean::make('Param 3', 'param_3'),

            new Tabs('Tabs 1', [
                new Tab('Tab 1', [
                    Boolean::make('Param 1', 'param_1'),
                    Boolean::make('Param 2', 'param_2'),
                    Boolean::make('Param 3', 'param_3'),
                ]),
                new Tab('Tab 2', [
                    Boolean::make('Param 1', 'param_1'),
                    Boolean::make('Param 2', 'param_2'),
                    Boolean::make('Param 3', 'param_3'),
                ]),
                new Tab('Tab 3', [
                    Boolean::make('Param 1', 'param_1'),
                    Boolean::make('Param 2', 'param_2'),
                    Boolean::make('Param 3', 'param_3'),
                ]),
            ]),
        ];
    }
}

Delcare your settings class in config/nova-settings.php

<?php

return [
    'model' => \Stepanenko3\NovaSettings\Models\Settings::class,

    'resource' => \Stepanenko3\NovaSettings\Resources\Settings::class,

    'types' => [
        \App\Nova\Settings\Demo::class, // Add this line
    ],
];

Usage

Click on the "Settings" menu item in your Nova app to see the tool.

Use helper function for access the settings

// settings(string|null $section, string|null $key = null, string|null $default = null, string|null $env = null)
settings('demo', 'key', 'defaultValue', config('app.env'))

Configuration

All the configuration is managed from a single configuration file located in config/nova-settings.php

Extends default model

Create your own model that will extends \Stepanenko3\NovaSettings\Models\Settings

// in app/Models/Settings.php

<?php

namespace App\Models;

use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;

class Settings extends \Stepanenko3\NovaSettings\Models\Settings
{
    use LogsActivity;

    public function getActivitylogOptions(): LogOptions
    {
        return LogOptions::defaults()
            ->logFillable()
            ->logOnlyDirty();
    }
}

Declare your model 'model' => \App\Models\Settings::class, in config/nova-settings.php

Extends default Nova resource

Create your own resource that will extends \Stepanenko3\NovaSettings\Resources\Settings

// in app/Nova/Settings.php

<?php

namespace App\Nova;

use Illuminate\Http\Request;
use Laravel\Nova\Fields\HasMany;

class Settings extends \Stepanenko3\NovaSettings\Resources\Settings
{
    public function fields(Request $request)
    {
        return array_merge(parent::fields($request), [
            HasMany::make('Activities', 'activities', 'App\Nova\ActivityLog'),
        ]);
    }
}

Declare your resource 'resource' => \App\Nova\Settings::class, in config/nova-settings.php

Don't forget to create App\Nova\ActivityLog

Screenshots

screenshot of tool

Credits

Contributing

Thank you for considering contributing to this package! Please create a pull request with your contributions with detailed explanation of the changes you are proposing.

License

This package is open-sourced software licensed under the MIT license.

You might also like...
This tool gives you the ability to set the default collapse state for Nova 4.0 menu items.

Nova Menu Collapsed This tool gives you the ability to set the default collapse state for Nova 4.0 menu items. Requirements php: =8.0 laravel/nova: ^

🖼️ Laravel Nova Field for uploading and cropping images using Slim Image Cropper
🖼️ Laravel Nova Field for uploading and cropping images using Slim Image Cropper

🖼️ Laravel Nova Field for uploading and cropping images using Slim Image Cropper

Laravel Livewire form component with declarative Bootstrap 5 fields and buttons.

Laravel Livewire Forms Laravel Livewire form component with declarative Bootstrap 5 fields and buttons. Requirements Bootstrap 5 Installation composer

Laravel Livewire (TALL-stack) form generator with realtime validation, file uploads, array fields, blade form input components and more.
Laravel Livewire (TALL-stack) form generator with realtime validation, file uploads, array fields, blade form input components and more.

TALL-stack form generator Laravel Livewire, Tailwind forms with auto-generated views. Support Contributions Features This is not an admin panel genera

A base API controller for Laravel that gives sorting, filtering, eager loading and pagination for your resources

Bruno Introduction A Laravel base controller class and a trait that will enable to add filtering, sorting, eager loading and pagination to your resour

Base library for repeated layout fields, content builders and other collection components

laravel-flexible-content This package's only purpose is to build custom repeated layout components, such as Laravel Nova's Flexible Content field or y

Library extra fields for Laravel Orchid Platform
Library extra fields for Laravel Orchid Platform

Orchid Fields Extra library which add different fields in Laravel Orchid Platform Installation You may install into your project using the Composer pa

A laravel package to handle model specific additional meta fields in an elegant way.

Laravel Meta Fields A php package for laravel framework to handle model meta data in a elegant way. Installation Require the package using composer: c

Store and retrieve settings generally or for model objects in Laravel.
Store and retrieve settings generally or for model objects in Laravel.

Store and retrieve settings generally or for model objects in Laravel. Documentation You can find the detailed documentation here in Laravel Settings

Comments
  • Bug with laravel/nova:4.18.2

    Bug with laravel/nova:4.18.2

    ErrorException Indirect modification of overloaded element of Stepanenko3\NovaSettings\Models\Settings has no effect vendor/laravel/framework/src/Illuminate/Collections/helpers.php:124 Illuminate\Foundation\Bootstrap\HandleExceptions::handleError vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php:259 Illuminate\Foundation\Bootstrap\HandleExceptions::Illuminate\Foundation\Bootstrap{closure} vendor/laravel/framework/src/Illuminate/Collections/helpers.php:124 data_set vendor/laravel/nova/src/Fields/Field.php:480 Laravel\Nova\Fields\Field::fillAttributeFromRequest vendor/laravel/nova/src/Fields/Field.php:463 Laravel\Nova\Fields\Field::fillAttribute vendor/laravel/nova/src/Fields/Field.php:445 Laravel\Nova\Fields\Field::fillInto vendor/laravel/nova/src/Fields/Field.php:419 Laravel\Nova\Fields\Field::fill vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:60 Illuminate\Support\HigherOrderCollectionProxy::Illuminate\Support{closure} [internal] array_map vendor/laravel/framework/src/Illuminate/Collections/Arr.php:560 Illuminate\Support\Arr::map vendor/laravel/framework/src/Illuminate/Collections/Collection.php:719 Illuminate\Support\Collection::map vendor/laravel/framework/src/Illuminate/Collections/HigherOrderCollectionProxy.php:61 Illuminate\Support\HigherOrderCollectionProxy::__call vendor/laravel/nova/src/FillsFields.php:100 Laravel\Nova\Resource::fillFields vendor/laravel/nova/src/FillsFields.php:43 Laravel\Nova\Resource::fillForUpdate vendor/laravel/nova/src/Http/Controllers/ResourceUpdateController.php:46 Laravel\Nova\Http\Controllers\ResourceUpdateController::Laravel\Nova\Http\Controllers{closure} vendor/laravel/framework/src/Illuminate/Database/Concerns/ManagesTransactions.php:30 Illuminate\Database\Connection::transaction vendor/laravel/nova/src/Http/Controllers/ResourceUpdateController.php:64 Laravel\Nova\Http\Controllers\ResourceUpdateController::__invoke vendor/laravel/framework/src/Illuminate/Routing/Controller.php:54 Illuminate\Routing\Controller::callAction vendor/laravel/framework/src/Illuminate/Routing/ControllerDispatcher.php:43 Illuminate\Routing\ControllerDispatcher::dispatch vendor/laravel/framework/src/Illuminate/Routing/Route.php:260 Illuminate\Routing\Route::runController vendor/laravel/framework/src/Illuminate/Routing/Route.php:205 Illuminate\Routing\Route::run vendor/laravel/framework/src/Illuminate/Routing/Router.php:727 Illuminate\Routing\Router::Illuminate\Routing{closure} vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:141 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/nova/src/Http/Middleware/Authorize.php:18 Laravel\Nova\Http\Middleware\Authorize::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/nova/src/Http/Middleware/BootTools.php:20 Laravel\Nova\Http\Middleware\BootTools::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/nova/src/Http/Middleware/DispatchServingNovaEvent.php:33 Laravel\Nova\Http\Middleware\DispatchServingNovaEvent::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/inertiajs/inertia-laravel/src/Middleware.php:92 Inertia\Middleware::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:50 Illuminate\Routing\Middleware\SubstituteBindings::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php:44 Illuminate\Auth\Middleware\Authenticate::handle vendor/laravel/nova/src/Http/Middleware/Authenticate.php:31 Laravel\Nova\Http\Middleware\Authenticate::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:78 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49 Illuminate\View\Middleware\ShareErrorsFromSession::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:121 Illuminate\Session\Middleware\StartSession::handleStatefulRequest vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:64 Illuminate\Session\Middleware\StartSession::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:67 Illuminate\Cookie\Middleware\EncryptCookies::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:116 Illuminate\Pipeline\Pipeline::then vendor/laravel/framework/src/Illuminate/Routing/Router.php:728 Illuminate\Routing\Router::runRouteWithinStack vendor/laravel/framework/src/Illuminate/Routing/Router.php:705 Illuminate\Routing\Router::runRoute vendor/laravel/framework/src/Illuminate/Routing/Router.php:669 Illuminate\Routing\Router::dispatchToRoute vendor/laravel/framework/src/Illuminate/Routing/Router.php:658 Illuminate\Routing\Router::dispatch vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:190 Illuminate\Foundation\Http\Kernel::Illuminate\Foundation\Http{closure} vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:141 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/livewire/livewire/src/DisableBrowserCache.php:19 Livewire\DisableBrowserCache::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/nova/src/Http/Middleware/ServeNova.php:23 Laravel\Nova\Http\Middleware\ServeNova::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21 Illuminate\Foundation\Http\Middleware\TransformsRequest::handle vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ConvertEmptyStringsToNull.php:31 Illuminate\Foundation\Http\Middleware\ConvertEmptyStringsToNull::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:21 Illuminate\Foundation\Http\Middleware\TransformsRequest::handle vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TrimStrings.php:40 Illuminate\Foundation\Http\Middleware\TrimStrings::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27 Illuminate\Foundation\Http\Middleware\ValidatePostSize::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/PreventRequestsDuringMaintenance.php:86 Illuminate\Foundation\Http\Middleware\PreventRequestsDuringMaintenance::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Http/Middleware/HandleCors.php:49 Illuminate\Http\Middleware\HandleCors::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Http/Middleware/TrustProxies.php:39 Illuminate\Http\Middleware\TrustProxies::handle vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:180 Illuminate\Pipeline\Pipeline::Illuminate\Pipeline{closure} vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:116 Illuminate\Pipeline\Pipeline::then vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:165 Illuminate\Foundation\Http\Kernel::sendRequestThroughRouter vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:134 Illuminate\Foundation\Http\Kernel::handle public/index.php:52 [main]

    opened by jeffersonsimaogoncalves 1
  • Helper function does not work properly

    Helper function does not work properly

    I have 2 issues with the helper function.

    1. Updating fields will not reset the cached value. You can manually fix this by listening to the events and resetting the cache.

    2. The helper will retrieve a value based on the "ENV" variable but will search in the database with the "ENV" and "TYPE" variable. So if you happen to use two types of settings you will mismatch the cached value. It will result in a blank value because the helper function won't search in the database as it already cached the other settings.

    $settings = Cache::remember('settings.' . $env, config('cache.lifetime'), function() use ($section, $env) {
        return config('nova-settings.model')::query()
            ->select('settings')
            ->where('slug', $section)
            ->where('env', $env)
            ->first()
            ->settings ?? [];
    });
    

    It should instead be;

    $settings = Cache::remember('settings.' . $env . $section, config('cache.lifetime'), function() use ($section, $env) {
        return config('nova-settings.model')::query()
            ->select('settings')
            ->where('slug', $section)
            ->where('env', $env)
            ->first()
            ->settings ?? [];
    });
    
    opened by Specialistinwebsites 1
  • Compatibility with fields that require additional JS

    Compatibility with fields that require additional JS

    It currently does not support "murdercode/Nova4-TinymceEditor" or "emilianotisato/nova-tinymce".

    This is only because it merges the fields to make them all save in the "settings" field. If overriding the fields method in the settings model with (new $this->type)->fields(); instead of (new $this->type)->getFields('settings') it'll work but it tries to save the fields in their corresponding field name in the database.

    Is it possible to manipulate this in any way?

    opened by Specialistinwebsites 1
  • dependsOn fields support

    dependsOn fields support

    does this package have dependsOn fields support?

    https://nova.laravel.com/docs/4.0/resources/fields.html#dependent-fields

    we are currently using outl1ne/nova-settings

    but having issues with dependsOn fields not working. Or thats not fair. they just havent implemented dependson functionality

    ref:

    • https://github.com/outl1ne/nova-settings/issues/138
    opened by chrillep 6
Releases(v1.0.4)
Owner
Artem Stepanenko
25 y.o. Web Developer 👨🏻‍💻 instagram.com/stepanenko3 t.me/stepanenko3
Artem Stepanenko
This Laravel Nova package adds a Trumbowyg field to Nova's arsenal of fields.

Nova Trumbowyg Field This Laravel Nova package adds a Trumbowyg field to Nova's arsenal of fields. Requirements php: >=8.0 laravel/nova: ^4.0 Installa

outl1ne 3 Sep 25, 2022
This Laravel Nova tool lets you run artisan and bash commands directly from Nova 4 or higher.

Laravel Nova tool for running Artisan & Shell commands. This Nova tool lets you run artisan and bash commands directly from nova. This is an extended

Artem Stepanenko 17 Dec 15, 2022
This Laravel Nova package allows you to manage media and media fields

Nova Media Hub This Laravel Nova package allows you to manage media and media fields. Requirements php: >=8.0 laravel/nova: ^4.0 Features Media Hub UI

outl1ne 25 Dec 22, 2022
Makes working with DateTime fields in Laravel's Nova easier

This package adds a DateTime field with support for a global DateTime format, syntactic sugar for formatting individual DateTime fields and powerful d

wdelfuego 6 Aug 4, 2022
.env vars check for Spatie's Laravel Health

Custom check for Spatie's Laravel Health - Ensure every .env variable you need has a value

Encodia 4 Nov 7, 2022
Fast and simple implementation of a REST API based on the Laravel Framework, Repository Pattern, Eloquent Resources, Translatability, and Swagger.

Laravel Headless What about? This allows a fast and simple implementation of a REST API based on the Laravel Framework, Repository Pattern, Eloquent R

Julien SCHMITT 6 Dec 30, 2022
Load .env files for PHP.

PHP DotEnv Loader Simple library to load and get values from .env file(s). Install composer require murilo-perosa/dot-env How to Use Namespace use Mur

Murilo Perosa 1 Jan 15, 2022
A minimalistic event calendar Tool for Laravel's Nova 4

Event calendar for Laravel Nova 4 An event calendar that displays Nova resources or other time-related data in your Nova 4 project on a monthly calend

wdelfuego 44 Jan 1, 2023
A Laravel Nova tool for viewing your application logs

This package makes it easy to view your Laravel application logs inside of Nova. It even supports polling. Installation You can install the Nova tool

The Laravel Framework 117 Dec 11, 2022
List of 77 languages for Laravel Framework 4, 5, 6, 7 and 8, Laravel Jetstream , Laravel Fortify, Laravel Breeze, Laravel Cashier, Laravel Nova and Laravel Spark.

Laravel Lang In this repository, you can find the lang files for the Laravel Framework 4/5/6/7/8, Laravel Jetstream , Laravel Fortify, Laravel Cashier

Laravel Lang 6.9k Jan 2, 2023