lmtc
lmtc
FFilament
Created by lmtc on 10/3/2024 in #❓┊help
weird question - dynamically generated tailwind config file after form submission
Yea that's exactly it, thanks, I'll move over to doing that - makes more sense anyway with tailwind 4 around the corner. Appreciate the help!
6 replies
FFilament
Created by lmtc on 10/3/2024 in #❓┊help
weird question - dynamically generated tailwind config file after form submission
@awcodes So I submit the form - it's a cluster page, and on handleUpdate after save I run a command that updates my existing tailwind.config.js file with some custom theme elements like colors, and some styles (button radius etc) , but the issue is I would then need to run a build - I should probably just use CSS variables but I thought this could be better since then I'm not generating a bunch of dynamic css variables - it's all in the config. This is mostly non-filament but would appreciate any advise - even if it's just saying that's a dumb idea don't do that haha
6 replies
FFilament
Created by lmtc on 8/17/2024 in #❓┊help
HasMany Table Relationship pivot/group RelationManager
I got this working:
protected function getTableQuery()
return $this->record->submissions()->groupBy('session_id')->getQuery();
}

protected function getTableColumns(): array
{
$fieldNames = $this->record->submissions()
->pluck('field_name')
->unique();

$columns = [];

foreach ($fieldNames as $field) {
$columns[] = TextColumn::make($field)
->label($field)
->getStateUsing(fn($record) => $this->getFieldValue($record, $field));
}

return $columns;
}

protected function getFieldValue(FormSubmissions $record, string $field)
{
return $record->where('session_id', $record->session_id)
->where('field_name', $field)
->value('field_value');
}

public function table(Table $table): Table
{
return $table
->query($this->getTableQuery())
->columns($this->getTableColumns())
->actions([
DeleteAction::make()
->action(function (FormSubmissions $record) {
FormSubmissions::where('session_id', $record->session_id)
->where('form_id', $record->form_id)
->delete();
})
->requiresConfirmation()
->label('Delete'),
])
->bulkActions([
BulkAction::make('deleteAll')
->action(function (Collection $records) {
// Retrieve unique session IDs from the selected records
$sessionIds = $records->pluck('session_id')->unique();

// Delete all submissions related to these session IDs
FormSubmissions::whereIn('session_id', $sessionIds)->delete();
})
->requiresConfirmation()
->label('Delete All'),
]);
}
protected function getTableQuery()
return $this->record->submissions()->groupBy('session_id')->getQuery();
}

protected function getTableColumns(): array
{
$fieldNames = $this->record->submissions()
->pluck('field_name')
->unique();

$columns = [];

foreach ($fieldNames as $field) {
$columns[] = TextColumn::make($field)
->label($field)
->getStateUsing(fn($record) => $this->getFieldValue($record, $field));
}

return $columns;
}

protected function getFieldValue(FormSubmissions $record, string $field)
{
return $record->where('session_id', $record->session_id)
->where('field_name', $field)
->value('field_value');
}

public function table(Table $table): Table
{
return $table
->query($this->getTableQuery())
->columns($this->getTableColumns())
->actions([
DeleteAction::make()
->action(function (FormSubmissions $record) {
FormSubmissions::where('session_id', $record->session_id)
->where('form_id', $record->form_id)
->delete();
})
->requiresConfirmation()
->label('Delete'),
])
->bulkActions([
BulkAction::make('deleteAll')
->action(function (Collection $records) {
// Retrieve unique session IDs from the selected records
$sessionIds = $records->pluck('session_id')->unique();

// Delete all submissions related to these session IDs
FormSubmissions::whereIn('session_id', $sessionIds)->delete();
})
->requiresConfirmation()
->label('Delete All'),
]);
}
12 replies
FFilament
Created by lmtc on 8/22/2024 in #❓┊help
Saving data on modal submission builder
when I click submit, it doesn't seem to save the whole form but it does set the field, I want it to save the whole form
10 replies
FFilament
Created by lmtc on 8/17/2024 in #❓┊help
HasMany Table Relationship pivot/group RelationManager
The custom view? This is my list submissions page:
public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);
$this->formSubmissions = $this->getPivotedFormSubmissions();
}

public function getPivotedFormSubmissions()
{
// Fetch all form submissions
$submissions = DB::table('form_submissions')
->where('form_id', $this->record->id)
->get();

// Group by session_id
$grouped = $submissions->groupBy('session_id');

// Extract all distinct field names
$fieldNames = $submissions->pluck('field_name')->unique();

// Pivot data using collections
$pivoted = $grouped->map(function ($items) use ($fieldNames) {
$pivot = ['session_id' => $items->first()->session_id];

foreach ($fieldNames as $field) {
$pivot[$field] = $items->firstWhere('field_name', $field)->field_value ?? null;
}

return $pivot;
});

return $pivoted->values(); // Resetting the keys
}
public function mount(int | string $record): void
{
$this->record = $this->resolveRecord($record);
$this->formSubmissions = $this->getPivotedFormSubmissions();
}

public function getPivotedFormSubmissions()
{
// Fetch all form submissions
$submissions = DB::table('form_submissions')
->where('form_id', $this->record->id)
->get();

// Group by session_id
$grouped = $submissions->groupBy('session_id');

// Extract all distinct field names
$fieldNames = $submissions->pluck('field_name')->unique();

// Pivot data using collections
$pivoted = $grouped->map(function ($items) use ($fieldNames) {
$pivot = ['session_id' => $items->first()->session_id];

foreach ($fieldNames as $field) {
$pivot[$field] = $items->firstWhere('field_name', $field)->field_value ?? null;
}

return $pivot;
});

return $pivoted->values(); // Resetting the keys
}
12 replies
FFilament
Created by lmtc on 8/22/2024 in #❓┊help
Saving data on modal submission builder
So the set is working from the action to the field in the actual form, but I want it to save the whole form on submit
10 replies
FFilament
Created by lmtc on 8/22/2024 in #❓┊help
Saving data on modal submission builder
I excluded the actual form - it's working to set the data outside, but ideally I don't want to have to hit save for the whole page since it's a bit annoying
10 replies
FFilament
Created by lmtc on 8/17/2024 in #❓┊help
HasMany Table Relationship pivot/group RelationManager
No description
12 replies
FFilament
Created by lmtc on 8/17/2024 in #❓┊help
HasMany Table Relationship pivot/group RelationManager
I have this working as a custom view but I'd rather use the default if it's at all possible
12 replies
FFilament
Created by lmtc on 8/17/2024 in #❓┊help
HasMany Table Relationship pivot/group RelationManager
So I have a form resource which has an id, I generate a form and store each field name and label against a session id, I then want to group it by session id and have a column for first_name and last_name with the values under it
12 replies
FFilament
Created by lmtc on 8/22/2024 in #❓┊help
Saving data on modal submission builder
@toeknee
BuilderComponent::make('blocks')
->label('')
->addActionLabel('Add Block')
->extraItemActions([
Action::make('add_component_styling')
->icon('heroicon-s-paint-brush')
->label('Styling Options')
->fillForm(function (
array $data,
array $arguments,
BuilderComponent $component
) {
$item_data = $component->getItemState($arguments['item']);
return [

];
})
->form([
])
->action(function (
array $data,
array $arguments,
Pages $record,
Set $set,
) {
$set('blocks.'.$arguments['item'].'.data.block_styling_options',
$data);
}),
])
->reorderableWithButtons()
->cloneable()
->collapsible()
->blocks([
BuilderComponent\Block::make('image')
->schema([
Hidden::make('block_styling_options'),
Grid::make(2)
->schema([
BuilderComponent::make('blocks')
->label('')
->addActionLabel('Add Block')
->extraItemActions([
Action::make('add_component_styling')
->icon('heroicon-s-paint-brush')
->label('Styling Options')
->fillForm(function (
array $data,
array $arguments,
BuilderComponent $component
) {
$item_data = $component->getItemState($arguments['item']);
return [

];
})
->form([
])
->action(function (
array $data,
array $arguments,
Pages $record,
Set $set,
) {
$set('blocks.'.$arguments['item'].'.data.block_styling_options',
$data);
}),
])
->reorderableWithButtons()
->cloneable()
->collapsible()
->blocks([
BuilderComponent\Block::make('image')
->schema([
Hidden::make('block_styling_options'),
Grid::make(2)
->schema([
10 replies
FFilament
Created by lmtc on 8/17/2024 in #❓┊help
HasMany Table Relationship pivot/group RelationManager
Bumping this - I've currently done it as a custom view - but would prefer to have it as a normal table
12 replies
FFilament
Created by myster on 2/17/2024 in #❓┊help
AWS S3 with Filament Laravel
It ended up being object ownership causing the issue
11 replies
FFilament
Created by myster on 2/17/2024 in #❓┊help
AWS S3 with Filament Laravel
@myster did you get this resolved?
11 replies
FFilament
Created by lmtc on 8/5/2024 in #❓┊help
Submitting form from Section header action
@Ron I ended up getting it working by redefining the record since it's always the same, not sure if this is the right approach?
->action(function (array $data) {
$this->record=Config::firstOrNew([
'config_type' => 'global_styling',
]);
$existing_data=$this->record->config_value;
$updated_data = array_merge($existing_data[0], $data);
$this->record->config_value = [$updated_data];
$this->record->save();
})
->action(function (array $data) {
$this->record=Config::firstOrNew([
'config_type' => 'global_styling',
]);
$existing_data=$this->record->config_value;
$updated_data = array_merge($existing_data[0], $data);
$this->record->config_value = [$updated_data];
$this->record->save();
})
5 replies
FFilament
Created by lmtc on 7/10/2024 in #❓┊help
Auto add empty repeater based on a value in another field
Yea but I want it to create X number of repeaters
4 replies
FFilament
Created by lmtc on 5/24/2024 in #❓┊help
Add X repeater items
Na, I mean have a modal where I set the number then add that number of items at once
5 replies
FFilament
Created by lmtc on 3/17/2024 in #❓┊help
performance in forms
I have moved what I can to extraitemactions and simplified, seems to have helped
7 replies
FFilament
Created by lmtc on 4/6/2024 in #❓┊help
generating a unique id for each builder block
Ended up customising the clone action:
->cloneAction(
fn(Action $action) => $action->action(function (
array $arguments,
BuilderComponent $component
): void {
$newUuid = $component->generateUuid();

$items = $component->getState();
$items[$newUuid] = $items[$arguments['item']];
$items[$newUuid]['data']['form_styling_id'] = Str::uuid()
->toString();

$component->state($items);

$component->collapsed(false,
shouldMakeComponentCollapsible: false);

$component->callAfterStateUpdated();
})
)
->cloneAction(
fn(Action $action) => $action->action(function (
array $arguments,
BuilderComponent $component
): void {
$newUuid = $component->generateUuid();

$items = $component->getState();
$items[$newUuid] = $items[$arguments['item']];
$items[$newUuid]['data']['form_styling_id'] = Str::uuid()
->toString();

$component->state($items);

$component->collapsed(false,
shouldMakeComponentCollapsible: false);

$component->callAfterStateUpdated();
})
)
4 replies
FFilament
Created by lmtc on 3/26/2024 in #❓┊help
getting the builder component id into a hidden field
Hidden::make('form_styling_id')
->default(function () {
return Str::uuid()
->toString();
}),
Hidden::make('form_styling_id')
->default(function () {
return Str::uuid()
->toString();
}),
5 replies