ngoquocdat
ngoquocdat
FFilament
Created by ngoquocdat on 10/21/2023 in #❓┊help
Custom property in CreateRecord form
Hello everyone, Currently, Filament doesn't provide built-in support for the belongsToMany relation in my specific case. Consequently, I've had to resort to using a custom property and managing the creation/editing process manually. What's peculiar is that this approach works seamlessly in the EditRecord context, but encounters an issue in CreateRecord. Upon submitting the form during record creation, the console reports the following error:
Livewire Entangle Error: Livewire property ['data.attributes.10'] cannot be found on component: ['app.filament.resources...']
Livewire Entangle Error: Livewire property ['data.attributes.10'] cannot be found on component: ['app.filament.resources...']
Here's a snippet from my resource form code:
Section::make(__('Attributes'))
->schema([
Grid::make(3)
->schema(function (Get $get): array {
$schema = [];

$attributes = CategoryAttribute::query()
->where('category_id', $get('category_id'))
->with('options')
->select('id', 'name')
->get();

foreach ($attributes as $attribute) {
$schema[] = Select::make("attributes.$attribute->id")
->required()
->label($attribute->name)
->options($attribute->options->pluck('name', 'id'))
->searchable();
}

return $schema;
})
])
->key('attributes'),
Section::make(__('Attributes'))
->schema([
Grid::make(3)
->schema(function (Get $get): array {
$schema = [];

$attributes = CategoryAttribute::query()
->where('category_id', $get('category_id'))
->with('options')
->select('id', 'name')
->get();

foreach ($attributes as $attribute) {
$schema[] = Select::make("attributes.$attribute->id")
->required()
->label($attribute->name)
->options($attribute->options->pluck('name', 'id'))
->searchable();
}

return $schema;
})
])
->key('attributes'),
EditRecord code:
protected function mutateFormDataBeforeFill(array $data): array
{
/** @var Product $record */
$record = $this->getRecord();

$attributes = $record->attributes->keyBy('id');

return [
...$data,
'attributes' => $attributes->map(fn ($attribute) => $attribute->pivot->value)->toArray(),
];
}
protected function mutateFormDataBeforeFill(array $data): array
{
/** @var Product $record */
$record = $this->getRecord();

$attributes = $record->attributes->keyBy('id');

return [
...$data,
'attributes' => $attributes->map(fn ($attribute) => $attribute->pivot->value)->toArray(),
];
}
2 replies
FFilament
Created by ngoquocdat on 10/19/2023 in #❓┊help
Dynamic form fields based on dependant fields
Hi guys, I have already read this section https://filamentphp.com/docs/3.x/forms/getting-started#dependant-fields, but this doesn't help me in this case. My case: In Product will have 1 category and a category will have many attributes. So in product form, when I change the category select, it will get all attributes of that category and show to form as field Is that possible to do that? Thank you for helping me.
2 replies
FFilament
Created by ngoquocdat on 9/18/2023 in #❓┊help
404 on own panel
No description
4 replies
FFilament
Created by ngoquocdat on 9/15/2023 in #❓┊help
Disabled tab
Hello, I've noticed that the Tab component has a disabled property, and I attempted to chain the ->disabled() method to it. However, I encountered an issue where the tab remains navigable despite setting it as disabled.
use Filament\Forms\Components\Tabs\Tab;

Tab::make('Tab')
->disabled()
->schema([]),
use Filament\Forms\Components\Tabs\Tab;

Tab::make('Tab')
->disabled()
->schema([]),
1 replies
FFilament
Created by ngoquocdat on 9/13/2023 in #❓┊help
Setup Filament test for Laravel app
No description
1 replies
FFilament
Created by ngoquocdat on 9/9/2023 in #❓┊help
Custom query in EditRecord
Hi guys, How to custom the query in EditRecord? I want to count the relastionship My code:
Section::make()
->schema([
Placeholder::make('courses_count')
->label(__('Total Courses'))
->content(fn (CourseCategory $record): ?string => $record->courses_count),
Placeholder::make('created_at')
->label('Created at')
->content(fn (CourseCategory $record): ?string => $record->created_at?->diffForHumans()),

Placeholder::make('updated_at')
->label('Last modified at')
->content(fn (CourseCategory $record): ?string => $record->updated_at?->diffForHumans()),
])
->columnSpan(['lg' => 1])
->hidden(fn (?CourseCategory $record) => $record === null),
Section::make()
->schema([
Placeholder::make('courses_count')
->label(__('Total Courses'))
->content(fn (CourseCategory $record): ?string => $record->courses_count),
Placeholder::make('created_at')
->label('Created at')
->content(fn (CourseCategory $record): ?string => $record->created_at?->diffForHumans()),

Placeholder::make('updated_at')
->label('Last modified at')
->content(fn (CourseCategory $record): ?string => $record->updated_at?->diffForHumans()),
])
->columnSpan(['lg' => 1])
->hidden(fn (?CourseCategory $record) => $record === null),
10 replies
FFilament
Created by ngoquocdat on 9/7/2023 in #❓┊help
Using Alpine.js inside the existing app with Filament table
Hi, I have a Laravel application and am using Alpine and have a Filament Table installed inside the application - app.js
import Alpine from 'alpinejs'

Alpine.data('some-data', () => ({
//
})

Alpine.start()
import Alpine from 'alpinejs'

Alpine.data('some-data', () => ({
//
})

Alpine.start()
- layouts/app.blade.php
@filamentScripts
<script src="{{ asset('js/app.js') }}"></script>
@filamentScripts
<script src="{{ asset('js/app.js') }}"></script>
But I'm having a problem: a javascript error is reported in the browser console when accessing a page that uses the Filament table.
Uncaught TypeError: Cannot read properties of undefined (reading '$on')
at Proxy.init (eval at safeAsyncFunction (app.js:605:14), <anonymous>:13:24)
at app.js:591:23
at tryCatch (app.js:545:12)
at evaluate (app.js:571:32)
at Function.<anonymous> (app.js:2924:27)
at flushHandlers (app.js:709:46)
at stopDeferring (app.js:714:5)
at deferHandlingDirectives (app.js:717:3)
at initTree (app.js:200:3)
at app.js:155:5
Uncaught TypeError: Cannot read properties of undefined (reading '$on')
at Proxy.init (eval at safeAsyncFunction (app.js:605:14), <anonymous>:13:24)
at app.js:591:23
at tryCatch (app.js:545:12)
at evaluate (app.js:571:32)
at Function.<anonymous> (app.js:2924:27)
at flushHandlers (app.js:709:46)
at stopDeferring (app.js:714:5)
at deferHandlingDirectives (app.js:717:3)
at initTree (app.js:200:3)
at app.js:155:5
So is there any way to fix this problem? Thanks guys.
2 replies
FFilament
Created by ngoquocdat on 7/23/2023 in #❓┊help
Use beautiful select field without make it searcheable?
1 replies
FFilament
Created by ngoquocdat on 7/2/2023 in #❓┊help
Form in page
9 replies
FFilament
Created by ngoquocdat on 5/20/2023 in #❓┊help
Generate form fields based on relationship when it was changed
Generate form fields based on relationship when it was changed
Select::make('category_id')
->relationship('category', 'name')
->required()
->reactive()
->preload()
->searchable()
->afterStateUpdated(function (string $state) {
$attributeGroups = CategoryAttributeGroup::query()
->where('category_id', $state)
->isVisible()
->with('categoryAttributes')
->get();
}),
...
Select::make('category_id')
->relationship('category', 'name')
->required()
->reactive()
->preload()
->searchable()
->afterStateUpdated(function (string $state) {
$attributeGroups = CategoryAttributeGroup::query()
->where('category_id', $state)
->isVisible()
->with('categoryAttributes')
->get();
}),
...
When the category was changed, i want to get all the attributes relationship of this category and show on the form schema as a select field ($attributeGroups is a list of attribute groups that have many attributes in that group). Is Filament can do that and how? Thanks guys
8 replies