exactwebitesolutions
exactwebitesolutions
FFilament
Created by exactwebitesolutions on 7/3/2024 in #❓┊help
Prevent concealed component check affecting input min/max behaviour?
No description
10 replies
FFilament
Created by exactwebitesolutions on 6/12/2024 in #❓┊help
Prevent extraAttributes escaping
No description
4 replies
FFilament
Created by exactwebitesolutions on 11/10/2023 in #❓┊help
Global search for resource name
How to include the resource name in the global search results? E.g search for 'Categories' would bring up the category resource.
2 replies
FFilament
Created by exactwebitesolutions on 10/30/2023 in #❓┊help
Render table component without a view
Is it possible to build a Filament table without a view file? Tried using Blade render but getting error:
Using $this when not in object context From inside <x-filament-tables::reorder.handle />
class ListExamples extends Component implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;

public function table(Table $table): Table
{
return $table
->query(Example::query())
->columns([
TextColumn::make('name'),
]);
}

public function render(): string
{
return Blade::render(<<<'BLADE'
<div>
{{ $table }}
</div>
BLADE, ['table' => $this->table]);
}
}
class ListExamples extends Component implements HasForms, HasTable
{
use InteractsWithTable;
use InteractsWithForms;

public function table(Table $table): Table
{
return $table
->query(Example::query())
->columns([
TextColumn::make('name'),
]);
}

public function render(): string
{
return Blade::render(<<<'BLADE'
<div>
{{ $table }}
</div>
BLADE, ['table' => $this->table]);
}
}
5 replies
FFilament
Created by exactwebitesolutions on 10/29/2023 in #❓┊help
Table filter below column?
Is it possible to use searchable(isIndividual: true) but with a select filter of options?
1 replies
FFilament
Created by exactwebitesolutions on 10/11/2023 in #❓┊help
Edit select form throwing error if not exists
If the select contains a value which does not exist in the relationship option then it throws
Filament\Forms\Components\Select::getEditOptionActionFormData(): Return value must be of type array, null returned
How to hide the form an show empty select. Tried this but still throws the error. If there are invalid data in the database e.g test_id=123 and this does not exist in the database, then the error is thrown when using the edit form
Select::make('test_id')
->relationship('example')
->editOptionForm(self::getFormSchema())
->editOptionAction(function (Forms\Components\Actions\Action $action) {
return $action
->visible(fn ($state, $record) => $state && $record)
Select::make('test_id')
->relationship('example')
->editOptionForm(self::getFormSchema())
->editOptionAction(function (Forms\Components\Actions\Action $action) {
return $action
->visible(fn ($state, $record) => $state && $record)
5 replies
FFilament
Created by exactwebitesolutions on 10/1/2023 in #❓┊help
Change the active relation manager tab
Is there a way of accessing the parent Resource from inside a RelationManager? E.g I want to change the tab after this action has been called but > Property [$parent] not found on component
->bulkActions([
Tables\Actions\DeleteBulkAction::make()
->after(function (ProductsRelationManager $livewire, Tables\Actions\DeleteBulkAction $action) {
$livewire->parent->activeRelationManager = array_key_first($livewire->parent->getRelationManagers());
}),
])
->bulkActions([
Tables\Actions\DeleteBulkAction::make()
->after(function (ProductsRelationManager $livewire, Tables\Actions\DeleteBulkAction $action) {
$livewire->parent->activeRelationManager = array_key_first($livewire->parent->getRelationManagers());
}),
])
I found $livewire->getPageClass() but this only returns the string
6 replies
FFilament
Created by exactwebitesolutions on 10/1/2023 in #❓┊help
Table columns support extract json?
Is it possible to extract a json data column into multiple filament table columns? e.g data = "{'foo':'yes', 'bar': 'no'}"
TextColumn::make('data>foo')->sortable(),
TextColumn::make('data>bar')->sortable()
TextColumn::make('data>foo')->sortable(),
TextColumn::make('data>bar')->sortable()
I know this can be done manually via the modifyQueryUsing and adding a raw select, just wondering if Filament has a handy way of doing it?
2 replies
FFilament
Created by exactwebitesolutions on 9/26/2023 in #❓┊help
Error on create with select and editOptionForm
Error
Filament\Forms\Components\Select::getEditOptionActionFormData(): Return value must be of type array, null returned
Forms\Components\Select::make('test')
->default(1)
->options([0 => 'test', 1 => 'test2'])
->editOptionForm([
Forms\Components\TextInput::make('test')
]),
Forms\Components\Select::make('test')
->default(1)
->options([0 => 'test', 1 => 'test2'])
->editOptionForm([
Forms\Components\TextInput::make('test')
]),
2 replies
FFilament
Created by exactwebitesolutions on 9/26/2023 in #❓┊help
Single FileUpload inside state path saves differently as json
Not sure if this is intended behaviour but the file upload with single upload is saving as json with a random key when it's used inside a statePath. E.g image = "icon1.svg" extra = "{ 'image': {'123':'icon2.svg'} }"
Forms\Components\FileUpload::make('image')->image(),

Forms\Components\Grid::make()
->statePath('extra')
->schema([
Forms\Components\FileUpload::make('image')->image(),
])
Forms\Components\FileUpload::make('image')->image(),

Forms\Components\Grid::make()
->statePath('extra')
->schema([
Forms\Components\FileUpload::make('image')->image(),
])
Tried to fix with afterStateUpdated but it's never called.
->afterStateUpdated(static function (BaseFileUpload $component, $state) {
///....
if ($component->isMultiple()) {
$component->state([(string) Str::uuid() => $state]);
} else {
$component->state($state);
}
})
->afterStateUpdated(static function (BaseFileUpload $component, $state) {
///....
if ($component->isMultiple()) {
$component->state([(string) Str::uuid() => $state]);
} else {
$component->state($state);
}
})
11 replies
FFilament
Created by exactwebitesolutions on 9/20/2023 in #❓┊help
Using suffix/prefix with html string
Adding a suffix looses the HtmlString object so it performs sanitization removing the tooltip.
Tables\Columns\TextColumn::make('total')
->html()
->formatStateUsing(fn (string $state) => new HtmlString("<span x-tooltip.raw='Example'>{$state}</span>"))
->suffix('test')
Tables\Columns\TextColumn::make('total')
->html()
->formatStateUsing(fn (string $state) => new HtmlString("<span x-tooltip.raw='Example'>{$state}</span>"))
->suffix('test')
This is a simplified example to show the issue we're actually overwriting the suffix for custom logic adding icons.
1 replies
FFilament
Created by exactwebitesolutions on 9/11/2023 in #❓┊help
Force deleting record error $record must not be accessed before initialization
When I delete a record the page shows an error before redirecting.
Typed property Filament\Resources\Pages\EditRecord::$record must not be accessed before initialization
protected function getActions(): array
{
return [
Actions\CreateAction::make()
->record($this->getRecord())
->url(fn ($record) => self::$resource::getUrl('create'))
];
}
protected function getActions(): array
{
return [
Actions\CreateAction::make()
->record($this->getRecord())
->url(fn ($record) => self::$resource::getUrl('create'))
];
}
7 replies
FFilament
Created by exactwebitesolutions on 9/9/2023 in #❓┊help
Adding a custom component that reuses choices js library
We have built a custom alpine component that uses choices.js. Is there a way of reusing the choices.js that's included with filament to save including this library twice?
4 replies
FFilament
Created by exactwebitesolutions on 8/26/2023 in #❓┊help
Where would you put action logic that handles validation?
Refactoring some duplicate code and wondering where you recommend putting validation logic for deletes on both DeleteAction and DeleteBulkAction. E.g
Tables\Actions\DeleteBulkAction::make()
->before(function (Tables\Actions\DeleteBulkAction $action) {
foreach ($action->getRecords() as $record) {

if ($record->staff()->exists()) {
Notification::make('not_deletable')
->warning()
->title('This record can not be deleted because it is in use')
->body(__('Reason why'))
->persistent()
->actions([
Action::make('staff')
->button()
->url(StaffResource::getUrl(
'index',
['tableFilters[project_id][value]' => $record->id]
)),
])
->send();

$action->cancel();

}
Tables\Actions\DeleteBulkAction::make()
->before(function (Tables\Actions\DeleteBulkAction $action) {
foreach ($action->getRecords() as $record) {

if ($record->staff()->exists()) {
Notification::make('not_deletable')
->warning()
->title('This record can not be deleted because it is in use')
->body(__('Reason why'))
->persistent()
->actions([
Action::make('staff')
->button()
->url(StaffResource::getUrl(
'index',
['tableFilters[project_id][value]' => $record->id]
)),
])
->send();

$action->cancel();

}
Filament\Actions\DeleteAction::make()
->before(function (Filament\Actions\DeleteAction $action) {
$record = $action->getRecord();

if ($record->staff()->exists()) {
Notification::make('not_deletable')
->warning()
->title('This record can not be deleted because it is in use')
->body(__('Reason why'))
->persistent()
->actions([
Action::make('staff')
->button()
->url(StaffResource::getUrl(
'index',
['tableFilters[project_id][value]' => $record->id]
)),
])
->send();

$action->cancel();

}
Filament\Actions\DeleteAction::make()
->before(function (Filament\Actions\DeleteAction $action) {
$record = $action->getRecord();

if ($record->staff()->exists()) {
Notification::make('not_deletable')
->warning()
->title('This record can not be deleted because it is in use')
->body(__('Reason why'))
->persistent()
->actions([
Action::make('staff')
->button()
->url(StaffResource::getUrl(
'index',
['tableFilters[project_id][value]' => $record->id]
)),
])
->send();

$action->cancel();

}
6 replies
FFilament
Created by exactwebitesolutions on 5/18/2023 in #❓┊help
How to load migrations for a test from inside a package?
Using the standard Filament plugin service provider by Spatie where the migrations are stored in .php.stub without the timestamp prefix. But how do you load the migrations in order for testing? I don't want to duplicate them and have tried passing the exact file paths but this gives the error:
The "1" argument does not exist. at vendor/symfony/console/Input/ArrayInput.php:188
protected function defineDatabaseMigrations()
{
$this->loadLaravelMigrations();

$this->loadMigrationsFrom(__DIR__.'/database/migrations');

$this->loadMigrationsFrom(ExampleSystem::getMigrations(true));
}
protected function defineDatabaseMigrations()
{
$this->loadLaravelMigrations();

$this->loadMigrationsFrom(__DIR__.'/database/migrations');

$this->loadMigrationsFrom(ExampleSystem::getMigrations(true));
}
public function getMigrations($with_path = false): array
{
$migrations = [
'create_table1',
'create_table1',
];

if ($with_path) {
$path = realpath(__DIR__.'/../database/migrations');

array_walk($migrations, fn (&$migration) => $migration = "{$path}/{$migration}.php.stub" );
}

return $migrations;
}
public function getMigrations($with_path = false): array
{
$migrations = [
'create_table1',
'create_table1',
];

if ($with_path) {
$path = realpath(__DIR__.'/../database/migrations');

array_walk($migrations, fn (&$migration) => $migration = "{$path}/{$migration}.php.stub" );
}

return $migrations;
}
public function configurePackage(Package $package): void
{
$package
->name(self::$name)
->hasMigrations(ExampleSystem::getMigrations());
}
public function configurePackage(Package $package): void
{
$package
->name(self::$name)
->hasMigrations(ExampleSystem::getMigrations());
}
6 replies
FFilament
Created by exactwebitesolutions on 5/3/2023 in #❓┊help
Close all notifications
Is there a way to trigger the close event on any persisted notifications?
9 replies
FFilament
Created by exactwebitesolutions on 5/3/2023 in #❓┊help
Add alpine data to filament modal
Is there a way of accessing the x-data from inside the header slot?
<button
type="button"
x-on:click="$dispatch('open-modal', {id: 'custom-modal'})"
>
Open
</button>

<x-filament::modal id="custom-modal">
<div x-data="{ name: 'Filament' }">
<x-slot name="header">
Name: <span x-text="name"></span>
</x-slot>

<div>
<input x-model="name" />
</div>
</div>
</x-filament::modal>
<button
type="button"
x-on:click="$dispatch('open-modal', {id: 'custom-modal'})"
>
Open
</button>

<x-filament::modal id="custom-modal">
<div x-data="{ name: 'Filament' }">
<x-slot name="header">
Name: <span x-text="name"></span>
</x-slot>

<div>
<input x-model="name" />
</div>
</div>
</x-filament::modal>
If I add x-data to x-filament::modal I get error with
can't access property "dispatchEvent", this.$refs.modalContainer is undefined
3 replies
FFilament
Created by exactwebitesolutions on 4/30/2023 in #❓┊help
Default sort direction for a column - descending first
To improve the UX I wanted to change how the ‘Updated at’ timestamp are sorted descending on first click of a column. I know you can change the default order for the whole table but here I'm referring to the individual column sorting - when you click on a column. On first click of a timestamp column you most likely want to see the recent first, and not oldest. If I reverse the direction in the query it kinda works but the label/arrow are incorrect.
Tables\Columns\TextColumn::make('updated_at')
->sortable(query: fn (Builder $query, string $direction): Builder =>
$query->orderBy('updated_at', $direction === 'asc' ? 'desc' : 'asc'))
Tables\Columns\TextColumn::make('updated_at')
->sortable(query: fn (Builder $query, string $direction): Builder =>
$query->orderBy('updated_at', $direction === 'asc' ? 'desc' : 'asc'))
2 replies
FFilament
Created by exactwebitesolutions on 4/28/2023 in #❓┊help
Use a custom view for overview card widget
How to use a custom view for an overview widget?
2 replies