MilenKo
MilenKo
Explore posts from servers
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
Wholly guaccamole... It was my silly mistake of trying to define the input form field as an array, e.g.
// All CheckboxList options: https://filamentphp.com/docs/3.x/forms/fields/checkbox-list
CheckboxList::make('site_checkboxlist[]') // checkbox list with supplied options
->options([
'1' => '== A ==',
'2' => '== B ==',
'3' => '== C =='
]),
// All CheckboxList options: https://filamentphp.com/docs/3.x/forms/fields/checkbox-list
CheckboxList::make('site_checkboxlist[]') // checkbox list with supplied options
->options([
'1' => '== A ==',
'2' => '== B ==',
'3' => '== C =='
]),
Must be one of all my attempts to please the array data storing... Once I removed it, I CONFIRM YOUR CODE WORKS !!! Thank you @awcodes you saved me a few more weeks of scratching my head...
27 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
No description
27 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
No description
27 replies
FFilament
Created by mile4841 on 8/27/2024 in #❓┊help
How to order naviation groups
I've moved out by setting a group icon and having sub menu items not having one as it makes more sense for my current project needs. By design filament allows either to have icon on the group but not on the items inside the group, or not to group the items and have an icon for any of the items on their own... It is what it is, I am not keen on modifying the filament code as I will have to deal with updates later and it will be a hassle, so for me this topic is closed now... 😉 (having other issues to tackle 😉 )
14 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
@awcodes Well, i would expect it to work as well, however there is an error the minute I switch to array type as it tries to store a string as an array and it does not allow it. I've posted it in the initial comment that switching string to array did not do the work. Here is the error from my previous message:
Cannot assign array to property App\Settings\GeneralSettings::$site_checkboxlist of type ?string
Cannot assign array to property App\Settings\GeneralSettings::$site_checkboxlist of type ?string
I've tried also to switch the type of the checkbox as a collection, however it seems like a method like ->collection() does not exist on the form inputs... Seems like the data passed is a JSON object of type: [ '1' => 'true', '2' => 'false' ] Or some other data sorting, but this should have been considered as a string, but it is actually considered as something strange to me, as I cannot define $site_checkboxlist as array, nor as string... Maybe I should try defining it as a JSON object somehow to test, but I don't find any useful information so far about that in the casts, and i've looked into many LaravelSettings casts to figure out which one should i use and how...
27 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
Tried to add this cast, but it was able to show the Settings page, but blew an error on storing the data: `php public static function casts(): array { return [ 'site_checkboxlist' => \Spatie\LaravelSettings\SettingsCasts\CollectionCast::class, ]; }
27 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
The idea is to add an example for all Form inputs so that if anybody needs to combine settings, can simply repurpose the template as they see fit without wondering like me how to add this or that or have the error I am facing with array<>string store.
27 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
@awcodes Here it is the repo with all it's perks. FYI, so far i only have installed a fresh Filament Admin panel with Laravel 11.x and added Larael Jetstream to improve the user logging experience adding 2FA. On top of that I've installed Filament Spatie Settings plugin and created the shared GeneralSettings.php extending Settings and GeneralSettingsPage.php responsible for the Settings form. Here is the github repo URL; https://github.com/mikemastercorp/filament-starter-kit
27 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
Sure thing, let me just commit it and will share the link here. It is not much as I said but I agree sometimes looking at pieces of code does not give the full picture.. Thanks anyway 😉
27 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
Steps to reproduce my "issue": 1. Install filament (I used latest from few days ago) 2. Install Spatie-Settings for filament. 3. Create a migration 4. Create a GeneralSettings settings page that extends the Settings class 5. Create the GeneralSettingsPage in filament/pages to show it to the navigation and inside of this page, try to use CheckboxList with the following code (or similar) 6. Try to store a few checkboxes `php // All CheckboxList options: https://filamentphp.com/docs/3.x/forms/fields/checkbox-list CheckboxList::make('site_checkboxlist') // checkbox list with supplied options ->options([ '1' => '== A ==', '2' => '== B ==', '3' => '== C ==' ]) // set the number of columns to order the list options (equal number of coluns and choices makes them horizonta) ->columns(3), // ->label('') // set an empty label value to hide it
27 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
There aren't any other modifications to official Filament but the migration, GeneralSettings..php and GeneralSettingsPage.php which I've shared. Here is the migration too in case it helps:
<?php

use Spatie\LaravelSettings\Migrations\SettingsMigration;

return new class extends SettingsMigration
{
public function up(): void
{
$this->migrator->add('general.site_name', 'Default Site Name'); // text input setting
$this->migrator->add('general.site_email', '[email protected]'); // text input with email validation
$this->migrator->add('general.site_select', ''); // select dropdown input
$this->migrator->add('general.site_is_checked', ''); // checkbox input
$this->migrator->add('general.site_is_toggled', ''); // toggle input
$this->migrator->add('general.site_checkboxlist', ''); // checkbox list input
$this->migrator->add('general.site_radio', ''); // radio options input
$this->migrator->add('general.meta_title', 'Default Meta Title'); // text input on another tab
$this->migrator->add('general.meta_description', 'Default Meta Description'); // demo text input for the second tab
}
};
<?php

use Spatie\LaravelSettings\Migrations\SettingsMigration;

return new class extends SettingsMigration
{
public function up(): void
{
$this->migrator->add('general.site_name', 'Default Site Name'); // text input setting
$this->migrator->add('general.site_email', '[email protected]'); // text input with email validation
$this->migrator->add('general.site_select', ''); // select dropdown input
$this->migrator->add('general.site_is_checked', ''); // checkbox input
$this->migrator->add('general.site_is_toggled', ''); // toggle input
$this->migrator->add('general.site_checkboxlist', ''); // checkbox list input
$this->migrator->add('general.site_radio', ''); // radio options input
$this->migrator->add('general.meta_title', 'Default Meta Title'); // text input on another tab
$this->migrator->add('general.meta_description', 'Default Meta Description'); // demo text input for the second tab
}
};
27 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
One type of cast I've found that can be suitable is ArraySerttingsCast but it requires some parameters and I am having hard time finding those
27 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
@awcodes Ive read it inside out but I am not really finding any clue as to what type of cast to use for storing an array of data to a single column... The only close example to my need was:
class GeneralSettings extends Settings
{
public string $site_name;

public bool $site_active;

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

public static function encrypted(): array
{
return [
'site_name'
];
}
}
class GeneralSettings extends Settings
{
public string $site_name;

public bool $site_active;

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

public static function encrypted(): array
{
return [
'site_name'
];
}
}
However in this example it is using the encrypted() method to encrypt the 'site_name' data
27 replies
FFilament
Created by Stricks on 9/27/2024 in #❓┊help
Trouble with Attach (Detach works)
I aggree more code is needed (unless it is prprietary) but otherwise there are only many GUESSES 🙂
53 replies
FFilament
Created by Stricks on 9/27/2024 in #❓┊help
Trouble with Attach (Detach works)
I mean dd the output you should get from the specific column and see if it even returns a value. Another thing can be if the model does not have the rifht to store the object data (guarder or filable properties are not set on the model)
53 replies
FFilament
Created by Stricks on 9/27/2024 in #❓┊help
Trouble with Attach (Detach works)
From what I know, Filament is smart enough to know the input field based on the column relation of the make() method, so if any record is stored in the DB matching the column name, filament should set it as a default and pre-populate as a selected option. That is why I aggree with @awcodes that there is something fishy with your relations... Check your relations using dd() or \Log()
53 replies
FFilament
Created by Stricks on 9/27/2024 in #❓┊help
Trouble with Attach (Detach works)
Any log errors? Or console debug output?
53 replies
FFilament
Created by Stricks on 9/27/2024 in #❓┊help
Trouble with Attach (Detach works)
->preloadRecordSelect() method is used to pre-load all selector options and not to populate a selected already and stored in DB record (if I understood correctly that is what was needed)
53 replies
FFilament
Created by Sean on 9/30/2024 in #❓┊help
Help with Builder - no JSON
I am not an expert in Filament to be honest but I think you've answered your question already with your latest statement as the builder uses the input name you defined in the static make() method. There has to be a way to manipulate maybe that, but for me this will be a high end acrobatics that I cannot assist much with (or not yet as I am just trying to go along with Filament and all it's magic tricks and abilities under the hood)
5 replies
FFilament
Created by MilenKo on 9/30/2024 in #❓┊help
Spatie Settings Checkboxlist
And here is my /app/Settings/GeneralSettings.php page code:
<?php

namespace App\Settings;

use Illuminate\Support\Collection;
use Spatie\LaravelSettings\Settings;

class GeneralSettings extends Settings
{
// Define the settings page inputs to use in the Settings Page
public string $site_name;
public string $site_email;
public string $site_select;
public string $site_is_checked;
public string $site_is_toggled;
public string $site_radio;
public string $meta_title;
public string $meta_description;

// Define the settings page inputs to use in the Settings Page
public string $site_checkboxlist = '';

// Use this function to return the settings group and its values
// In a view we can use: <h1>{{ settings(App\Settings\GeneralSettings::class)->site_name }}</h1>
public static function group(): string
{
return 'general';
}
}
<?php

namespace App\Settings;

use Illuminate\Support\Collection;
use Spatie\LaravelSettings\Settings;

class GeneralSettings extends Settings
{
// Define the settings page inputs to use in the Settings Page
public string $site_name;
public string $site_email;
public string $site_select;
public string $site_is_checked;
public string $site_is_toggled;
public string $site_radio;
public string $meta_title;
public string $meta_description;

// Define the settings page inputs to use in the Settings Page
public string $site_checkboxlist = '';

// Use this function to return the settings group and its values
// In a view we can use: <h1>{{ settings(App\Settings\GeneralSettings::class)->site_name }}</h1>
public static function group(): string
{
return 'general';
}
}
27 replies