e are build a settings plugin using 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
Copy composer require queents/settings-module
Add Module to modules_statuses.json
if not exists
Make a migration
Publish Assets
Copy npm i & npm run build
OR
Setting Page Generator
to create a new settings page you can use this command
Copy 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
Copy 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:
Copy 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:
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
Copy <? 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
this method take a key of setting and return the payload of it
it's take the value of money and return it on the money format