Skip to content

Settings Configuration

In Ozu, you can define a settings class to manage global website configurations such as social links, footer addresses, or any other site-wide parameters.

Creating the Settings Class

To create your settings, you must define a class that extends Code16\OzuClient\Support\Settings\OzuSiteSettings.

Each property you define in this class becomes a "website setting". You can provide default values directly in the class.

php
namespace App\Support;

use Code16\OzuClient\Support\Settings\OzuSiteSettings;
use Code16\OzuClient\OzuCms\OzuSettingsFormConfig;
use Code16\OzuClient\OzuCms\Form\OzuField;

class WebsiteSettings extends OzuSiteSettings
{
    public string $facebook_url = 'https://facebook.com/my-page';
    public string $contact_email = 'contact@example.com';
    public string $footer_address = '123 Main St, City';

    public static function configureSettingsForm(OzuSettingsFormConfig $config): OzuSettingsFormConfig
    {
        return $config
            ->addSettingField(
                OzuField::makeText('facebook_url')
                    ->setLabel('Facebook URL')
            )
            ->addSettingField(
                OzuField::makeText('contact_email')
                    ->setLabel('Contact Email')
                    ->setValidationRules(['email'])
            )
            ->addSettingField(
                OzuField::makeEditor('footer_address')
                    ->setLabel('Footer Address')
            );
    }
}

Overriding Settings in Ozu Dashboard

By implementing the configureSettingsForm(...) method, you allow these properties to be overridden directly in Ozu's CMS.

  • Each field added via addSettingField should correspond to a property defined in your class.
  • When a value is saved in the CMS, it will automatically override the default value defined in your PHP class at deployment.
  • The OzuSiteSettings base class handles the retrieval of these values (using Laravel's Cache) and populates your object's properties.

NOTE

Settings form fields are synced with Ozu CMS by using the php artisan ozu:configure command.

Using Ozu CMS's defined settings locally

You can pull your settings from Ozu locally with the import command: php artisan ozu:import --settings

WARNING

When you pull settings from Ozu, they are saved in the application cache, so you have to define a working cache driver in your .env file.

Registering the Settings Class

Once your class is created, you need to register it in your config/ozu-client.php configuration file:

php
// config/ozu-client.php

return [
    // ...
    'settings' => \App\Support\WebsiteSettings::class,
];

Using Settings

You can use your settings anywhere in your application by instantiating the class or resolving it from the container:

php
$settings = app(\App\Support\WebsiteSettings::class);

echo $settings->facebook_url;
// or
echo $settings->get('facebook_url');