GithubHelp home page GithubHelp logo

jeffersonsimaogoncalves / stepanenko3-laravel-nova-settings Goto Github PK

View Code? Open in Web Editor NEW

This project forked from stepanenko3/nova-settings

2.0 0.0 0.0 168 KB

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

License: MIT License

PHP 100.00%

stepanenko3-laravel-nova-settings's Introduction

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.

stepanenko3-laravel-nova-settings's People

Contributors

stepanenko3 avatar

Stargazers

Oybek Kayumov avatar Gábor Mihálcz avatar

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.