Sjoerd24
Sjoerd24
FFilament
Created by Sjoerd24 on 11/14/2024 in #❓┊help
[Importer] Only update values that are empty/null
So I am writing a lot of importers and exporters, love the proces. Now i have a bit of a weird problem, I have a table "suppliers" and there I want the following behaviour: 1) Supplier doesnt exist, create new one 2) Supplier does exist: only update values that are missing. One is easy, but how can I do two? What is the most efficient way to do this? Maybe sth like:
protected function beforeUpdate(): void
{
// check here all fields if they are changed and if so reset? (ugly solution!)
}
protected function beforeUpdate(): void
{
// check here all fields if they are changed and if so reset? (ugly solution!)
}
Should be some easier way right?
4 replies
FFilament
Created by Sjoerd24 on 8/7/2024 in #❓┊help
Re-enter password when switching panels?
I have different panels, some have more sensitive information than others. I want that if user switch to their personal information panel that they re enter a password or a personal code to gain access. How can you implement something like that? Also when they leave the panel the “special privileges “ should expire immediately. I first thought by setting a special setting and checking for it in a middleware but maybe there is a better solution?
3 replies
FFilament
Created by Sjoerd24 on 6/2/2024 in #❓┊help
extraModalFooterActions, retrieving post $data?
I have a system to make schedules, schedules can be recurring. I want to have an extra FooterAction to "Save all future recurring schedules" instead of just the current one. Got that all to work with this (https://filamentphp.com/docs/3.x/actions/modals#adding-an-extra-modal-action-button-to-the-footer) But the problem is I cant add a requireConfirmation() to it then. That works with this perfectly BUT i can't retrieve the form $data (because it is a child?) Is there any method to fix this? My code:
return Actions\EditAction::make()
->modalHeading(__('Edit shift'))
->form(ScheduleResource::getFormSchema())
->modalSubmitActionLabel(__('Edit only this shift'))
->extraModalFooterActions([
Action::make('editAll')
->label(__('Edit all future shifts'))
->requiresConfirmation()
->action(function (Schedule $record, array $data) {
dd($data);
// returns null :(
})
,
Action::make('delete')
->hiddenLabel()
->icon('heroicon-s-trash')
->color('danger')
->requiresConfirmation()
->tooltip(__('Delete this shift'))
->cancelParentActions()
->action(function (Schedule $record) {
$record->delete();
$this->refreshRecords();
}),
return Actions\EditAction::make()
->modalHeading(__('Edit shift'))
->form(ScheduleResource::getFormSchema())
->modalSubmitActionLabel(__('Edit only this shift'))
->extraModalFooterActions([
Action::make('editAll')
->label(__('Edit all future shifts'))
->requiresConfirmation()
->action(function (Schedule $record, array $data) {
dd($data);
// returns null :(
})
,
Action::make('delete')
->hiddenLabel()
->icon('heroicon-s-trash')
->color('danger')
->requiresConfirmation()
->tooltip(__('Delete this shift'))
->cancelParentActions()
->action(function (Schedule $record) {
$record->delete();
$this->refreshRecords();
}),
I feel like maybe this could help (https://discord.com/channels/883083792112300104/1237435510100594719/1237599157187903558) but maybe I am missing something obivous?
7 replies
FFilament
Created by Sjoerd24 on 5/20/2024 in #❓┊help
web push notifications for filament
Does anyone here have experience integrating this package: https://github.com/laravel-notification-channels/webpush With filament? It looks pretty straightforward, but i was hoping somebody already did this and has some tips on how you accomplish a nice integration. Would love for example to just select some important notifications from filament and then push them with “->webpush” to certain users. Would be a great plugin idea, would for sure pay also for sth like this. 🙂
2 replies
FFilament
Created by Sjoerd24 on 5/10/2024 in #❓┊help
Making a (readonly) Repeater with a custom query
Current setup
2 replies
FFilament
Created by Sjoerd24 on 5/9/2024 in #❓┊help
Editing select label with pivot values
I have this form in a repeater form:
Forms\Components\Select::make('user_id')
->label(__('User'))
->relationship('user', 'name')
->live(onBlur: true)
->disabled(fn($record) => $record?->is_absent)
->distinct()
->disableOptionsWhenSelectedInSiblingRepeaterItems()
Forms\Components\Select::make('user_id')
->label(__('User'))
->relationship('user', 'name')
->live(onBlur: true)
->disabled(fn($record) => $record?->is_absent)
->distinct()
->disableOptionsWhenSelectedInSiblingRepeaterItems()
Now I am trying that the text "(absent)" appears after the username if is_absent ==true. I tried it with formatStateUsing and getOptionLabelFromRecordUsing(), but I just can't get it to work because i need the values from the relationship and the current (pivot) record. I am probably doing something stupid, but could someone point me in the right direction?
5 replies
FFilament
Created by Sjoerd24 on 4/1/2024 in #❓┊help
Accessing $request vars in observer
So I ran into this problem multiple times but always changed it differently. I'm now posting this hoping there is an easier solution. Sometimes I use fields in my form (for recurring event for example) that I don't need saved in the database. If I don't specify the fields in the fillable array (on the model) then they don't appear in the observer:
public function creating(Schedule $schedule): void
{
// recurrence_weekdays is set in the form but not in fillable
$schedule->recurrence_weekdays // this will be null
// if I try this:
$request = request();
$request->input('recurrence_weekdays');
// the result is also null, but if I check with dd the array the data is in there. It just looks like because it is send with livewire everything gets a bit weird.
}
public function creating(Schedule $schedule): void
{
// recurrence_weekdays is set in the form but not in fillable
$schedule->recurrence_weekdays // this will be null
// if I try this:
$request = request();
$request->input('recurrence_weekdays');
// the result is also null, but if I check with dd the array the data is in there. It just looks like because it is send with livewire everything gets a bit weird.
}
I know i should maybe do this with a: ->mutateFormDataUsing() But I would have to do that at multiple places (in the resource and livewire page with fullcalendar for example), and personally I love putting this logic in an observer so I always know where to look. So my question: how can I access $_POST vars (or $request->inputs) in an observer? Without adding them as a fillable field?
3 replies
FFilament
Created by Sjoerd24 on 2/29/2024 in #❓┊help
Registering a resource page in the main navigation
So i have a resource Devices with many many categories. Now i made a separate List view to just show a subsets of those categories. (With its own selection of tabs) That all works fine, i just can’t figure out if it is possible to register this extra ListOtherDevices in the main navigation. I tried setting the getParentNavigation and getNavigationLabel but that doesn’t seem to work. Record sub navigation also isn’t an option because it should apply to the List overview pages. Anyone knows if this is possible?
5 replies
FFilament
Created by Sjoerd24 on 2/29/2024 in #❓┊help
stacking table rows, how do you do this?
I know you can stack two fields in a table row but then you lose the label on top of it. In the attached file you can see a example that this is possible (in multiple columns), but how do you do this? Or is this done with formatStateUsing ?
5 replies
FFilament
Created by Sjoerd24 on 1/25/2024 in #❓┊help
what does ->prose do?
Simple question but i can’t find it by googling or searching the docs. I had some trouble displaying html and after searching the demo app I learned that adding ->prose() fixed all my problems. But what does this function do exactly? And is there a reason it isn’t in the docs? I would like to add it but since I don’t understand what it does.. 😅
5 replies
FFilament
Created by Sjoerd24 on 1/16/2024 in #❓┊help
User not linked to tenant > redirect to new tenant page
So the question if pretty straighforward, after a new user has registered in my Filament panel he/she is not yet linked to a tenant (if they are invited this is already arranged,but not every user is invited of course). The problem is I need to redirect a user that isn't linked to a tenant to go to (in my case) "clinic/new". I think the code should be something like this:
user is logged in but not linked to a tenant, redirect to register clinic page
if (!Filament::getTenant() && $request->url <> url('/clinic/new')) {
return redirect('/clinic/new');
}
user is logged in but not linked to a tenant, redirect to register clinic page
if (!Filament::getTenant() && $request->url <> url('/clinic/new')) {
return redirect('/clinic/new');
}
But where do I put this code? Stupid question probably but I cant figure it out. I tried a middleware but that doesn't seem to work, I suspect an 404 error is given earlier in the chain. Anybody any tips? btw: I use Shield with spatie permissions Teams for authentication.
6 replies
FFilament
Created by Sjoerd24 on 1/3/2024 in #❓┊help
Creating relationship, changing query? (spatie teams/multi-tenancy)
No description
8 replies
FFilament
Created by Sjoerd24 on 12/14/2023 in #❓┊help
Richeditor problem, images do upload when marked private but not public?
I have a strange problem, and I also found others with the issue (https://discord.com/channels/883083792112300104/1178647784757416016). So the problem is: If I use the following code:
Forms\Components\RichEditor::make('content')
->fileAttachmentsDisk('s3-public')
->fileAttachmentsDirectory('protocol_files')
->fileAttachmentsVisibility('private')
Forms\Components\RichEditor::make('content')
->fileAttachmentsDisk('s3-public')
->fileAttachmentsDirectory('protocol_files')
->fileAttachmentsVisibility('private')
Images are uploaded to my bucket and visible for like 5 minutes or something. (temp url expires, file stays in the bucket) Not very useful, but if I use the following:
Forms\Components\RichEditor::make('content')
->fileAttachmentsDisk('s3-public')
->fileAttachmentsDirectory('protocol_files')
->fileAttachmentsVisibility('public')
Forms\Components\RichEditor::make('content')
->fileAttachmentsDisk('s3-public')
->fileAttachmentsDirectory('protocol_files')
->fileAttachmentsVisibility('public')
The file is not uploaded or added the content field. I don't get any errors which make debugging a lot harder. If I use SpatieMediaLibrary I can upload files to the s3-public bucket so the connection should be working (as is also evident in the fact if I mark them private it also does work). Is this a filament bug? I already looked through the source code of filament but my skill is insufficient to comprehend. 😅 I will try to make a bugreport if others have the same problem! Edit: just tried out TinyEditor plugin (https://github.com/mohamedsabil83/filament-forms-tinyeditor/blob/2.x/docs/usage-and-customization.md) and exactly the same behaviour! I think they use filament under the hood for uploading the images?
2 replies
FFilament
Created by Sjoerd24 on 11/16/2023 in #❓┊help
Transferring a value from the main form to an optionForm, is this possible?
No description
10 replies
FFilament
Created by Sjoerd24 on 10/30/2023 in #❓┊help
Accessing variables from within createOptionForm
Hope anyone can help me, the question boils down to: Is it possible to receive form values from within an createOptionForm? I am running some tests but I'm afraid it isn't possible..? If I try to retrieve a value from outside the optionform like this: Forms\Components\Select::make('some_id') [etc] ->createOptionForm([ Forms\Components\Select::make('message') ->live(onBlur: true) ->afterStateUpdated(function (Get $get, Set $set) { $set(target_id', $get('some_id')); }) Forms\Components\Select::make('target_id') [etc] It also doesn't receive any values. It works fine if I try to retrieve for example the message and transfer that to the target_id. I'm guessing this is because only the form is loaded with livewire.. Is this just not possible? Or are there other solutions?
1 replies