Sauravisus
Sauravisus
FFilament
Created by Sauravisus on 1/9/2024 in #❓┊help
Display all translations
Howdy, is there a way to display all translations used by a model using the Spatie Translatable plugin? Like, if I have a name column, and it gets translated to 4 languages. How would I go about displaying all 4 languages at the same time, rather than having to edit, save, swap language, edit, save, etc.?
6 replies
FFilament
Created by Sauravisus on 10/25/2023 in #❓┊help
Adding a save button to EditPage header
So I'm trying to move the save button from the form actions to the header actions, and snatching it out of there with parent::getFormActions() and putting that into my header actions does show the button, but the button itself doesn't work, as it's no longer within the form tag. How would I go about adding a custom action that actually saves the form currently being viewed in an edit page? It's a standard EditRecord page we're talking about here.
protected function getHeaderActions(): array
{
$actions = parent::getFormActions();

return [
Arr::first($actions)->action('save'),
Action::make('optimized')
->label('Mark as Optimized')
->requiresConfirmation()
->action(function (Task $task) {
$task->calculateNewDeadline();
$this->refreshFormData([
'status',
'urgency',
]);
}),
Arr::last($actions)
];
}
protected function getHeaderActions(): array
{
$actions = parent::getFormActions();

return [
Arr::first($actions)->action('save'),
Action::make('optimized')
->label('Mark as Optimized')
->requiresConfirmation()
->action(function (Task $task) {
$task->calculateNewDeadline();
$this->refreshFormData([
'status',
'urgency',
]);
}),
Arr::last($actions)
];
}
This is how I grabbed the buttons from the edit form. The cancel button works fine, but that's just a link so it should. Only the save button isn't working as intended. It's the Arr::first($actions) one in that list.
11 replies
FFilament
Created by Sauravisus on 10/15/2023 in #❓┊help
TextColumn vanishes when using dot notation
So I've got this TextColumn component in a table
Tables\Columns\TextColumn::make('client.website')
->label('Website')
->formatStateUsing(fn (string $state) => Str::remove('https://', $state))
->url(function (string $state) {
if(Str::startsWith($state, ['https://', 'http://'])) {
return $state;
}
return 'https://'.$state;
}, true)
->toggleable()
->searchable(),
Tables\Columns\TextColumn::make('client.website')
->label('Website')
->formatStateUsing(fn (string $state) => Str::remove('https://', $state))
->url(function (string $state) {
if(Str::startsWith($state, ['https://', 'http://'])) {
return $state;
}
return 'https://'.$state;
}, true)
->toggleable()
->searchable(),
And if I just name it website it shows up but is empty (as my model doesn't have a website field, so that's as expected) When I name it client.website, it just disappears as if the column isn't defined at all. It also isn't shown in the column picker. The relationship defined on my model is like this:
public function client()
{
return $this->belongsTo(Client::class);
}
public function client()
{
return $this->belongsTo(Client::class);
}
This used to work, like 2 days ago, but now it doesn't. I've got no idea why this'd be the case. Last thing I did that could influence the query for the table is this:
->modifyQueryUsing(function (Builder $query) {
if (!request()->user()->hasRole('Super Admin')) {
return $query->where('assigned_to', request()->user()->id);
}
return $query;
})
->modifyQueryUsing(function (Builder $query) {
if (!request()->user()->hasRole('Super Admin')) {
return $query->where('assigned_to', request()->user()->id);
}
return $query;
})
But removing it doesn't return the column at all.
10 replies
FFilament
Created by Sauravisus on 10/14/2023 in #❓┊help
Is there a way to add pagination to a repeater component?
So I've got a repeater field, that could potentially get hundreds of entries. Is there a way to do pagination on them, or is that a pipe-dream for the time being?
9 replies
FFilament
Created by Sauravisus on 10/14/2023 in #❓┊help
Toggling editability on fields in a repeater
I've got a repeater with 2 fields in it. While on the edit view I need the textarea disabled, and the checkbox hidden by default. Then, I need a button to "unlock" those fields for editing. As in, show the checkbox and un-disable the textarea. Yes, it sounds wacky, but it's what my client wants I'm afraid. 😅 I tried using live() on the toggle, and having both disabled() and hidden() use the value from a toggle outside the repeater to try and do what I wanted but that didn't seem to work.
20 replies
FFilament
Created by Sauravisus on 10/7/2023 in #❓┊help
Inlining the label of textinput
Is there an option that allows this? Kinda like how you can inline the label of a checkbox or a togge?
5 replies
FFilament
Created by Sauravisus on 10/6/2023 in #❓┊help
DefaultSort on a Repeater
I've been searching high and low, but couldn't find an answer to this. Is there a way to decide the sorting order for items in a repeater? This is my repeater and its components:
Repeater::make('notes')
->relationship('notes')
->schema([
Forms\Components\Textarea::make('contents')
->label(fn (Get $get) => User::whereId($get('creator'))->first()->full_name . " - Created at: " . Carbon::parse($get('created_at')) ?? 'Add Note')
->maxLength(65535)
->required(),
Forms\Components\Checkbox::make('send_as_email')
->hiddenOn('view')
->label('Send note as email to client?')
->helperText('This sends the contents of the note to the client of this task, as an email.')
->default(false),
])
->mutateRelationshipDataBeforeCreateUsing(function (array $data) {
$data['creator'] = auth()->id();
return $data;
})
->columnSpanFull()
->defaultItems(0),
Repeater::make('notes')
->relationship('notes')
->schema([
Forms\Components\Textarea::make('contents')
->label(fn (Get $get) => User::whereId($get('creator'))->first()->full_name . " - Created at: " . Carbon::parse($get('created_at')) ?? 'Add Note')
->maxLength(65535)
->required(),
Forms\Components\Checkbox::make('send_as_email')
->hiddenOn('view')
->label('Send note as email to client?')
->helperText('This sends the contents of the note to the client of this task, as an email.')
->default(false),
])
->mutateRelationshipDataBeforeCreateUsing(function (array $data) {
$data['creator'] = auth()->id();
return $data;
})
->columnSpanFull()
->defaultItems(0),
I want to sort this by created_at so the newest is at the top; Is there a way I can do this?
14 replies