# Settings

<figure><img src="/files/0q0xb1ruEYdQWwepLyiJ" alt=""><figcaption></figcaption></figure>

e are build a settings plugin using [spatie-laravel-settings](https://github.com/spatie/laravel-settings) so you can use full package feature by creating the setting class and migration and we will help you to generate a page for it

### Install

```bash
composer require queents/settings-module
```

Add Module to `modules_statuses.json` if not exists

```json
{
    "Settings": true
}
```

Make a migration

```bash
php artisan migrate
```

Publish Assets

```bash
npm i & npm run build
```

OR

```bash
yarn & yarn build
```

### Setting Page Generator

to create a new settings page you can use this command

```bash
php artisan vilt:setting
```

and put the setting name like `SiteMap` and your Module name

go to `Modules/YourModuleName/Database/Migrations` and you will get the main setting migration set your values

go to `Modules/YourModuleName/Settings` and add your settings as a public vars and set the group name

go to `Modules/YourModuleName/Pages` and you will get the settings Page edit the rows to be your selected rows type

### Setting Class

the page Setting class will be look like this

```php
class GeneralSettings extends Settings
{
    public string $site_name;

    public bool $site_active;

    public static function group(): string
    {
        return 'general';
    }
}
```

### Setting Migration

This command will create a new file in `Modules/ModuleName/Database/Migrations` where you can add the properties and their default values:

```php
use Spatie\LaravelSettings\Migrations\SettingsMigration;

class CreateGeneralSettings extends SettingsMigration
{
    public function up(): void
    {
        $this->migrator->add('general.site_name', 'Spatie');
        $this->migrator->add('general.site_active', true);
    }
}
```

We add the properties site\_name and site\_active here to the general group with values Spatie and true. More on migrations later

You should migrate your database to add the properties:

```bash
php artisan migrate
```

now you are ready for a settings page

### Settings page

our generator generate a Setting Page for you to view your settings and update it

```php
<?php

namespace Modules\Settings\Pages;

use Illuminate\Support\Str;
use Modules\Base\Helpers\Resources\Menu;
use Modules\Base\Helpers\Resources\Row;
use Modules\Base\Helpers\Resources\Setting;
use Modules\Settings\Settings\GoogleSettings;
use Modules\Settings\Settings\SitesSettings;

namespace Modules\Settings\Pages;

use Modules\Base\Helpers\Resources\Row;
use Modules\Base\Services\Rows\Email;
use Modules\Base\Services\Rows\Media;
use Modules\Base\Services\Rows\Repeater;
use Modules\Base\Services\Rows\Tel;
use Modules\Base\Services\Rows\Text;
use Modules\Base\Services\Rows\Textarea;
use Modules\Settings\Services\Setting;
use Modules\Settings\Settings\SitesSettings;

class SiteSettingsPage extends Setting {

    public ?string $setting = SitesSettings::class;
    public ?bool $api = true;
    public ?string $path = "site_settings";
    public ?string $group = "Settings";
    public ?string $icon = "bx bxs-cog";

    public  function rows(): array
    {
        return [
            Text::make('site_name')->label(__('Site Name')),
            Text::make('site_description')->label(__('Site Description')),
            Text::make('site_keywords')->label(__('Site Keywords')),
            Media::make('site_profile')->label(_('Site Profile')),
            Media::make('site_logo')->label(__('Site Logo')),
            Text::make('site_author')->label(__('Site Author')),
            Textarea::make('site_address')->label(__('Site Address'))->type('textarea'),
            Email::make('site_email')->label(__('Site Email'))->type('email'),
            Tel::make('site_phone')->label(__('Site Phone'))->type('tel'),
            Text::make('site_phone_code')->label(_('Site Phone Code')),
            Text::make('site_location')->label(__('Site Location')),
            Text::make('site_currency')->label(__('Site Currency')),
            Text::make('site_language')->label(__('Site Language')),
            Repeater::make('site_social')->label(__('Site Social'))->type('repeater')->options([
                Text::make('vendor')->label(__('Vendor')),
                Text::make('url')->label(__('URL')),
            ]),
            Repeater::make('site_menu')->label(__('Site Menu'))->type('repeater')->options([
                Text::make('title')->label(__('Title')),
                Text::make('icon')->label(__('Icon')),
                Text::make('target')->label(__('Target'))->type('switch'),
                Text::make('url')->label(__('URL')),
                Text::make('route')->label(__('Route')),
            ]),
        ];
    }

}
```

it will generate a full settings page for you.

you can generate 'Action', 'Widget', 'Modal' and use it on the Setting Page like a Resource

### Settings Helpers

we build a helper function for settings you can use it very simple

```php
settings(key)
```

this method take a key of setting and return the payload of it

```php
dollar(double)
```

it's take the value of money and return it on the money format


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://queents.gitbook.io/vilt/plugins/settings.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
