natindonesia / filament-demo

MIT License
0 stars 0 forks source link

Create Settings Page #6

Open Ticlext-Altihaf opened 1 month ago

Ticlext-Altihaf commented 1 month ago

    public static function setAppName(string $appName)
    {
        // hacking env
        $envFile = app()->environmentFilePath();
        $str = file_get_contents($envFile);
        // sanitizing, only allow alphanumeric, underscore, and space
        $appName = preg_replace("/[^a-zA-Z0-9_ ]+/", "", $appName);
        // warp in double quote
        $appName = '"' . $appName . '"';
        $str = preg_replace("/APP_NAME=(.*)/", "APP_NAME=$appName", $str); //hopium
        file_put_contents($envFile, $str);
    }
Ticlext-Altihaf commented 1 month ago
  1. Create custom page in the default panel
  2. Add Livewire forms to the custom page
  3. Add TextInput
  4. In the mount function load app name from config
  5. Create submit function that call setAppName the function need to be triggered when users click it

Reference: https://github.com/natindonesia/learning-diary-web/blob/master/app/Filament/Admin/Pages/AppSettings.php