PHP code example of quadrubo / filament-model-settings

1. Go to this page and download the library: Download quadrubo/filament-model-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/ */

    

quadrubo / filament-model-settings example snippets


public static function getSettingRecord()
{
    return auth()->user();
}

public function form(Form $form): Form
{
    return $form
        ->schema([
            Forms\Components\Select::make('theme')
                ->options([
                    'dark' => 'Dark Mode',
                    'light' => 'Light Mode',
                    'high_contrast' => 'High Contrast',
                ]),
        ]);
}

use App\Filament\Admin\Pages\ManagePreferences;

class AdminPanelProvider extends PanelProvider
{
    public function panel(Panel $panel): Panel
    {
        return $panel
            ->
            ...
            ->userMenuItems([
                MenuItem::make()
                    ->label('Settings')
                    ->url(fn (): string => ManagePreferences::getUrl())
                    ->icon('heroicon-o-cog-6-tooth'),
            ]);
    }
}

namespace App\Filament\Admin\Pages;

class ManagePreferences extends ModelSettingsPage implements HasModelSettings
{
    public static function shouldRegisterNavigation(): bool
    {
        return false;
    }
}

namespace App\Models;

use Glorand\Model\Settings\Traits\HasSettingsField;

class School extends Model
{
    use HasSettingsField;

    public $defaultSettings = [
        'color' => '#ff0000',
        'can_add_students' => true,
    ];
}

namespace App\Filament\Resources;

class SchoolResource extends Resource
{
    public static function form(Form $form): Form
    {
        return $form
            ->schema([
                Forms\Components\ColorPicker::make('settings.color_1')
                    ->isModelSetting(),
                Forms\Components\Toggle::make('settings.can_add_students')
                    ->isModelSetting(),
            ]);
    }
}

Forms\Components\Toggle::make('school_stuff.can_add_students')
    ->isModelSetting('school_stuff'),
bash
php artisan vendor:publish --tag="filament-model-settings-views"
bash
php artisan make:filament-model-settings-page ManagePreferences