PHP code example of visanduma / nova-settings

1. Go to this page and download the library: Download visanduma/nova-settings library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

visanduma / nova-settings example snippets





return [
     /* default path for load settings class */
    'settings_path' => app_path('Nova/Settings'),
];


use Visanduma\NovaSettings\HasNovaSettings;

class User extends Authenticatable
{
    use HasNovaSettings;

}


public function tools()
{
        return [
            /* other tools */
            \Visanduma\NovaSettings\NovaSettings::make(),

        ];
}


class Contact extends NovaSettingsMum

{

    public $icon = 'phone';


    public function fields()

    {

        return [

            Text::make('Name')->rules('       'NC' => 'North Central',
                'N' => 'Northern',
            ]),

            Country::make('Country')->rules('

namespace App\Nova\Settings;

public function boot()

{
        NovaSettings::register([
            Contact::class,
        ]);
}

public $icon = 'bell';

 public function label():string

 {

    return 'User contacts';

 }

 public function uriKey(): string

 {
    return 'user-contacts';
 }

    protected bool $global = false;

protected function getModel()
{
    return Auth::user(); // default model is Auth User
}

use Visanduma\NovaSettings\NovaSettings;

// getting single value
NovaSettings::get('contact.name', 'default value');

nova_settings('contact.name','default value');

// getting whole settings array
NovaSettings::get('contact');

nova_settings('contact');

// use different Model instead Auth User
NovaSettings::get('contact.name', 'default value', Admin::find(3));

nova_settings('contact.name','default value', Admin::find(3));


// getting global settings
NovaSettings::global('system.email');

NovaSettings::global('system');

nova_settings_global('system.phone'),

protected function transformInputs(array $inputs): array

{
    // do your modifications

    return $inputs;
}

protected function afterSaved(NovaRequest $request)

{
        // this method will be called after the form is saved
}

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

php artisan migrate


php artisan nova-settings:make Contact