BuddhaNature
BuddhaNature
FFilament
Created by BuddhaNature on 11/18/2024 in #❓┊help
How can I add a client side error message to FileUpload?
When uploading a file that is either not the correct file type, or larger than 2 megabytes, the light gray "x" icon jiggles, but I'd like to add a client side error message as to why the error occurred. It seems that `->validationMessages()" does not do this. How can I add friednly messages specific to each validation?
FileUpload::make('image')
->maxSize(2048)
->acceptedFileTypes(['image/png', 'image/jpeg']);
FileUpload::make('image')
->maxSize(2048)
->acceptedFileTypes(['image/png', 'image/jpeg']);
4 replies
FFilament
Created by BuddhaNature on 11/13/2024 in #❓┊help
Creating a child Table class that uses inheritance on a List page.
Hi All, I have been using inheritance to create custom classes for Filament objects I want to customize. For example:
class SectionForInfolist extends \Filament\Infolists\Components\Section
{
public function myFeature(): static
{
// Do stuff
return $this;
}
}
class SectionForInfolist extends \Filament\Infolists\Components\Section
{
public function myFeature(): static
{
// Do stuff
return $this;
}
}
However, I am having trouble figuring out how to use a custom Table class, because of the way that Filament "makes" tables and then injects them:
class ListPage extends ListRecords
{
public function table(MyCustomTable $table): MyCustomTable
{
}
}
class ListPage extends ListRecords
{
public function table(MyCustomTable $table): MyCustomTable
{
}
}
Doing this results in a "must be compatible with Filament\Tables\Table" error. Diving into the source shows that the Table is made elsewhere and injects some Livewire stuff. In my case, I can't use the global settings as per the docs because I want to create custom methods in the child class not just define defaults. Does anyone have experience with this and can lend some advice on how to use a custom Table class that can be used on a List page?
2 replies
FFilament
Created by BuddhaNature on 9/15/2024 in #❓┊help
In a Table Filter, how can I query a JSON element that is an array instead of a value?
Hi, In a Table Filter, how can I query a JSON element that is an array instead of a value? For example, Let's assume the following in a column named data:
{
"genre": "Science Fiction",
"tags": [
"future",
"robots",
"speculative"
]
}
{
"genre": "Science Fiction",
"tags": [
"future",
"robots",
"speculative"
]
}
Using the following ENUMs: Genre Enum
case SciFi = 'Science Fiction';
case Romance = 'Romance';
case History = 'History';
case Fantasy = 'Fantasy';
case SciFi = 'Science Fiction';
case Romance = 'Romance';
case History = 'History';
case Fantasy = 'Fantasy';
Tags Enum
case Future = 'Future';
case Robots = 'Robots';
case Speculative = 'Speculative';
case HeroJourney = 'Hero\'s Journey';
case Travel = 'Travel';
case Future = 'Future';
case Robots = 'Robots';
case Speculative = 'Speculative';
case HeroJourney = 'Hero\'s Journey';
case Travel = 'Travel';
If I want to filter by genre, I can do this, which works fine:
SelectFilter::make('data->genre')
->label('Genre')
->multiple()
->options(GenreEnum::class),
SelectFilter::make('data->genre')
->label('Genre')
->multiple()
->options(GenreEnum::class),
However, the same does not work for tags because they are arrays. Anything I pick never matches.
SelectFilter::make('data->tags')
->label('Tags')
->multiple()
->options(TagEnum::class),
SelectFilter::make('data->tags')
->label('Tags')
->multiple()
->options(TagEnum::class),
How can I create a filter using the tags in data->tags?
4 replies
FFilament
Created by BuddhaNature on 9/5/2024 in #❓┊help
Will mounting an action keep parameters from being seen by the world?
When mounting an action in Filament PHP, are the arguments exposed to the browser (and potentially visible to a user inspecting the data) or are they strictly processed on the backend, ensuring they are not publicly visible? Source : https://github.com/filamentphp/filament/blob/e5778290382f0ba8e37657cf541884d2a2f2785b/packages/actions/src/Concerns/InteractsWithActions.php#L159 This is the method in question:
public function mountAction(string $name, array $arguments = []): mixed
public function mountAction(string $name, array $arguments = []): mixed
Example of a call that I'd like to keep the data private on:
$this->mountAction('mySuperDuperAction', [
'first_name' => 'Clark',
'last_name' => 'Kent',
'secret_identity' => 'Superman',
'social_security_number' => 'krypton-123-4567',
'secret_crush' => 'Lex Luthor',
]);
$this->mountAction('mySuperDuperAction', [
'first_name' => 'Clark',
'last_name' => 'Kent',
'secret_identity' => 'Superman',
'social_security_number' => 'krypton-123-4567',
'secret_crush' => 'Lex Luthor',
]);
14 replies
FFilament
Created by BuddhaNature on 7/23/2024 in #❓┊help
How to pass form data when using replaceMountedAction()
Hi, I've created a header action with a form that replaces itself with another action. I need help passing the form data from the first action to the second. I've reviewed the docs and read up on passing $data and $arguments, but I can't get it to work. The goal is for the first action to appear as a modal where the user can enter search terms. When entered, those keywords are passed as part of $data to the next action that is mounted so I can show the user their keywords. Can anyone help me figure this out. I've provided the relevant code here.
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Infolists\Components\TextEntry;
use Filament\Resources\Pages\ViewRecord;

class Discord extends ViewRecord
{
// Other Filament stuff

public function getHeaderActions(): array
{
return [
Action::make('search')
->action(function (array $data) {
$this->replaceMountedAction('results', $data);
})
->form(
[
TextInput::make('keywords'),
]
)
->modal()
->slideOver(),
];
}


public function resultsAction(): Action
{
return Action::make('results-picker')
->action(function (array $data) {
// Do API things
})
->infolist(
[
TextEntry::make('keyword')
->label('These are the keywords you picked')
->getStateUsing(function ($data) {
return $data['keywords'];
}),
]
)
->modal()
->slideOver();
}
}
use Filament\Actions\Action;
use Filament\Forms\Components\TextInput;
use Filament\Infolists\Components\TextEntry;
use Filament\Resources\Pages\ViewRecord;

class Discord extends ViewRecord
{
// Other Filament stuff

public function getHeaderActions(): array
{
return [
Action::make('search')
->action(function (array $data) {
$this->replaceMountedAction('results', $data);
})
->form(
[
TextInput::make('keywords'),
]
)
->modal()
->slideOver(),
];
}


public function resultsAction(): Action
{
return Action::make('results-picker')
->action(function (array $data) {
// Do API things
})
->infolist(
[
TextEntry::make('keyword')
->label('These are the keywords you picked')
->getStateUsing(function ($data) {
return $data['keywords'];
}),
]
)
->modal()
->slideOver();
}
}
2 replies
FFilament
Created by BuddhaNature on 7/9/2024 in #❓┊help
How can I add a DeleteAction to View Page that does not have an Index page as part of its resource?
Hi, I have a resource called "Books" that has a relation called "Notes." I want a Notes record to have a landing/View page that can be bookmarked, but I can't figure out how to do that. I tried creating a Note Resource with just a View page like this:
public static function getPages(): array
{
return [
'view' => NoteViewPage::route('/{record}'),
];
}
public static function getPages(): array
{
return [
'view' => NoteViewPage::route('/{record}'),
];
}
Infolists work as expected. Edit actions work as expected, but when I add a Delete action, I get a route index not found error. I don't want to have to make an index page because that's not how I want the end user to interact with Notes. How can I get around the route not found error so that I can have a view page with an edit and delete action?
1 replies
FFilament
Created by BuddhaNature on 7/8/2024 in #❓┊help
How can I store a single data key in a JSON column cast as an array without deleting other keys?
I have a table called "Books" with a "notes" column.
Schema::create('books', static function (Blueprint $table): void {
// Other columns
$table->json('notes')->nullable();
});
Schema::create('books', static function (Blueprint $table): void {
// Other columns
$table->json('notes')->nullable();
});
The "notes" column is cast as an array.
protected $casts = [
'notes' => 'array',
];
protected $casts = [
'notes' => 'array',
];
The data that is being stored, looks something like this:
{
"brief_synopsis": "*sample text*",
"international": "*sample text*",
"long_summary": "*sample text*",
"formatting_notes": "*sample text*"
}
{
"brief_synopsis": "*sample text*",
"international": "*sample text*",
"long_summary": "*sample text*",
"formatting_notes": "*sample text*"
}
The problem that I am having is that when I create an Edit action that edits only one element, all of the others are set to null because a new array with a single key (the current one) is overwriting the entire field. I tried books->brief_synopsis, but that does not work either.
EditAction::make('Edit')
->label('Edit the brief synopsis)
->form([
RichEditor::make('books.brief_synopsis'),
])
->modal();
EditAction::make('Edit')
->label('Edit the brief synopsis)
->form([
RichEditor::make('books.brief_synopsis'),
])
->modal();
How can I set up my Edit action to update the target element without erasing the other elements?
1 replies
FFilament
Created by BuddhaNature on 6/27/2024 in #❓┊help
When using EditAction in an ActionGroup, how can the icon be removed?
No description
10 replies
FFilament
Created by BuddhaNature on 5/29/2024 in #❓┊help
How can the resource query be modified on an Infolist page?
Hi, When loading a resource, the standard select uses *. On a table page, I can use modifyQueryUsing() to modify the resource to suit the table's needs, but I don't see a way to do that with a View page that doesn't have a modifyQueryUsing() method either on the Page or the Infolist.
6 replies
FFilament
Created by BuddhaNature on 5/10/2024 in #❓┊help
nestedRecursiveRules
How can I add custom messages to nestedRecursiveRules() in a tag input? In the example below, I get the following error: "The mountedActionsData.0.tags.7 field must not be greater than 25 characters."
TagsInput::make('tags')
->rules(['max:10'])
->validationMessages([
'max' => 'You can only add up to :max tags.',
])
->nestedRecursiveRules([
'min:3',
'max:25',
]);
TagsInput::make('tags')
->rules(['max:10'])
->validationMessages([
'max' => 'You can only add up to :max tags.',
])
->nestedRecursiveRules([
'min:3',
'max:25',
]);
10 replies
FFilament
Created by BuddhaNature on 4/4/2024 in #❓┊help
Show which tabs have form errors when a form is submitted
I have an "Infolist" page with entries organized in tabs. To keep the UI consistent and a pleasant experience for the user, the edit action displays all of the form elements in the same tab structure in the form. The problem I am facing is that when the form is submitted and re-rendered with validation errors, it's not clear where the validation errors are because the page is reset back to the first tab on submit. The end user does not know where the validation error is and has to click on each individual tab. Has anyone come up with a solution to a problem like this? Is there a way to either highlight a tab with errors or add a badge with a count of errors?
1 replies
FFilament
Created by BuddhaNature on 3/4/2024 in #❓┊help
How can I force a modal to a view when a view page exists.
Hi, I have an action that links to a view page, but I'd also like to have a link to a preview page of that view page as a modal. I am using the following code:
ActionGroup::make([
ViewAction::make()
->slideOver()
->modalHeading('Lorem ipsum dolor sit amet, consectetur adipiscing elit.')
->modalDescription('Aenean mollis elit eget ullamcorper venenatis.')
->label('Preview')
->icon(''),
ViewAction::make()
->label('Full View')
->icon(''),
]),
ActionGroup::make([
ViewAction::make()
->slideOver()
->modalHeading('Lorem ipsum dolor sit amet, consectetur adipiscing elit.')
->modalDescription('Aenean mollis elit eget ullamcorper venenatis.')
->label('Preview')
->icon(''),
ViewAction::make()
->label('Full View')
->icon(''),
]),
The second View action works perfectly and links to the view page. But the first View action does not act as a modal and instead links directly to the view page. How can I get the preview link to work as a modal?
6 replies
FFilament
Created by BuddhaNature on 2/5/2024 in #❓┊help
How can I add a locale as a url parameter on a panel?
I tried adding a locale parameter to my code so that instead of this:
public function panel(Panel $panel): Panel
{
return $panel
->id('books')
//
->path('books/');
}
public function panel(Panel $panel): Panel
{
return $panel
->id('books')
//
->path('books/');
}
I have this:
public function panel(Panel $panel): Panel
{
return $panel
->id('books')
//
->path('books/{locale}');
}
public function panel(Panel $panel): Panel
{
return $panel
->id('books')
//
->path('books/{locale}');
}
But that did not work.
9 replies
FFilament
Created by BuddhaNature on 2/2/2024 in #❓┊help
How can I remove the resource name from all action buttons such as "create"?
How can I remove the resource name from all action buttons such as "create"? For example, If I have a "Book" resource and a "Movie" resource, I end up with "Create Book" and "Create movie" buttons assuming the action is "Create." I'd like the button to omit the resource name without having to explicitly use a label() method because I don't want to lose localization options. The end result I'm looking for is to have a simple "Create" button that is localized without having to localize the resource name/label.
1 replies
FFilament
Created by BuddhaNature on 1/18/2024 in #❓┊help
How can I add an asterisk next to a required field when using ->rules(['required'])?
No description
4 replies
FFilament
Created by BuddhaNature on 1/15/2024 in #❓┊help
unsavedChangesAlerts() does not work and generates an error
No description
6 replies
FFilament
Created by BuddhaNature on 1/10/2024 in #❓┊help
How can I limit the query on just one page using getEloquentQuery()
Hi. I don't need all the columns of a resource for my list page. How can I create a select() that only applies to the list page?
9 replies
FFilament
Created by BuddhaNature on 1/10/2024 in #❓┊help
Using $navigationGroup with getRecordSubNavigation()
Is there a way to group sub-navigation presented with getRecordSubNavigation() using something similar to $navigationGroup? I tried $navigationGroup and it didn't work.
1 replies
FFilament
Created by BuddhaNature on 11/20/2023 in #❓┊help
Preventing the display of a related resource on a view or edit page.
How can I prevent the display of a resource on either a view or an edit page?
6 replies
FFilament
Created by BuddhaNature on 11/20/2023 in #❓┊help
What is the performance difference between `->resources()` and `->discoverResources()`?
How much more performance is gained by using ->resources() instead of discovery via ->discoverResources().
2 replies