sven
sven
FFilament
Created by sven on 7/18/2024 in #❓┊help
Spatie media images get very small after upload
No description
2 replies
FFilament
Created by sven on 7/10/2024 in #❓┊help
Custom action before EditRecord
Hi, I want to show an Action to the user when they want to publish a record. More specifically, I have a Collection model, and an Article model. A Collection has many articles. When the user wants to publish the collection, I want to show a modal to select articles to publish along with the collection. I'd like to show a modal that lets the user select the associated articles to publish with the collection. At the moment the user has to select the article records in the relation manager and publish them there. I'd like to integrate those two actions. I tried different things but can't figure out from the docs if this would be possible as there seem to be quite a lot of functions to tap into, along with custom actions etc. Any help?
3 replies
FFilament
Created by sven on 2/3/2024 in #❓┊help
Validate MorphedByMany pivot table
I have a many-to-many polymorphic Author (authorable) relation in my schema. The pivot table also has a role_id that links to an author_roles table. In my ArticleResource I now built a relation manager between the Article model and Author relation. The idea is that users can attach Authors and specify the AuthorRole in an AttachAction on the relation manager. It's possible to add an author to the same record multiple times, but not with the same role. (eg. The author could be both an writer and editor of the article.) I now want to write a Unique validation rule to check that the author_id, authorable_type, authorable_id, AND author_role_id are unique. I'm struggling to understand where to get the data and how to access the pivot data to enforce the unique validation rule. Another possibility could be not to show the duplicate option in the first place, or disable it. But I'm not sure how to get the pivot data from Filament This is what I have so far..
(...)->headerActions([
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->recordTitle(function ($record) {
return "{$record->first_name} {$record->last_name}";
})
->recordSelect(
fn (Select $select) => $select
->placeholder('Select an author')
)
->recordSelectSearchColumns(['first_name', 'last_name'])
->form(fn (Tables\Actions\AttachAction $action, RelationManager $livewire, $record): array => [
$action->getRecordSelect(),
Forms\Components\Select::make('author_role_id')
->preload()
->options(
AuthorRole::pluck('role_name', 'id')->toArray()
)
->searchable()
->required()
->label('Role')
])->label('Add existing')->unique(modifyQueryUsing: function() {
... ?
}),
(...)->headerActions([
Tables\Actions\AttachAction::make()
->preloadRecordSelect()
->recordTitle(function ($record) {
return "{$record->first_name} {$record->last_name}";
})
->recordSelect(
fn (Select $select) => $select
->placeholder('Select an author')
)
->recordSelectSearchColumns(['first_name', 'last_name'])
->form(fn (Tables\Actions\AttachAction $action, RelationManager $livewire, $record): array => [
$action->getRecordSelect(),
Forms\Components\Select::make('author_role_id')
->preload()
->options(
AuthorRole::pluck('role_name', 'id')->toArray()
)
->searchable()
->required()
->label('Role')
])->label('Add existing')->unique(modifyQueryUsing: function() {
... ?
}),
2 replies
FFilament
Created by sven on 1/7/2024 in #❓┊help
Using SpatieMediaLibraryFileUpload in form tabs
When I try to add the SpatieMediaLibraryFileUpload form component to a Filament\Forms\Components\Tabs\Tab component I get the following error: "Filament\Forms\Components\SpatieMediaLibraryFileUpload::Filament\Forms\Components{closure}(): Argument #2 ($file) must be of type string, array given". Can anyone help me with this? Here is the full code I'm trying to implement:
Tabs::make('Media')
->tabs([
Tabs\Tab::make('Upload')
->schema([
SpatieMediaLibraryFileUpload::make('media')
->label('')
->openable()
->preserveFilenames()
->imageEditor()
->customProperties(['caption' => 'my caption'])
->getUploadedFileNameForStorageUsing(function (TemporaryUploadedFile $file): string {
return str($file->getClientOriginalName())->prepend(now()->timestamp);
})
->multiple()
->panelLayout('grid')
->reorderable()
]),
Tabs\Tab::make('Meta')
->schema([
Repeater::make('media')
->relationship()
->schema([
TextInput::make('custom_properties.caption'),
KeyValue::make('custom_properties'),
ViewField::make('file_name')
->label('File')
->view('filament.forms.components.media')
]),
]),
])
Tabs::make('Media')
->tabs([
Tabs\Tab::make('Upload')
->schema([
SpatieMediaLibraryFileUpload::make('media')
->label('')
->openable()
->preserveFilenames()
->imageEditor()
->customProperties(['caption' => 'my caption'])
->getUploadedFileNameForStorageUsing(function (TemporaryUploadedFile $file): string {
return str($file->getClientOriginalName())->prepend(now()->timestamp);
})
->multiple()
->panelLayout('grid')
->reorderable()
]),
Tabs\Tab::make('Meta')
->schema([
Repeater::make('media')
->relationship()
->schema([
TextInput::make('custom_properties.caption'),
KeyValue::make('custom_properties'),
ViewField::make('file_name')
->label('File')
->view('filament.forms.components.media')
]),
]),
])
4 replies