MohamedSabil83
MohamedSabil83
FFilament
Created by MohamedSabil83 on 2/23/2024 in #❓┊help
Anyway to apply filter forms like dashboard in a custom page which include table?
I had a custom page not related to a resource which have table and some widgets. I know that can expose filtering from table to widget but, I wondering if can apply a top filter forms like what can be applied to the dashboard (Feature start from v3.1)
7 replies
FFilament
Created by MohamedSabil83 on 11/26/2023 in #❓┊help
How to reload select's options?
I have a select of categories which options loaded from relation, and hintAction to create new category. Anyway to reload the options after adding an item?
4 replies
FFilament
Created by MohamedSabil83 on 10/16/2023 in #❓┊help
Select createOptionForm not saved with the record
I have the following code which it works in v2 but not after upgrade to v3. The category saved and appeared in the select, but when save the form it's not saved with the created model.
Forms\Components\Select::make('category_id')
->label(__('validation.attributes.category'))
->relationship('category', 'name', fn ($query) => $query->with('parent'))
->getOptionLabelFromRecordUsing(fn ($record) => collect([$record->parent?->name, $record->name])->filter()->join(' - '))
->required()
->searchable()
->preload()
->createOptionForm([
Forms\Components\TextInput::make('name')
->label(__('validation.attributes.name'))
->autocomplete(false)
->required()
->rule(fn ($livewire) => UniqueJsonRule::for(table: 'shop_categories', column: 'name', locale: $livewire->activeLocale)),
Forms\Components\Select::make('parent_id')
->label(__('validation.attributes.parent_category'))
->placeholder(__('Leave it empty to be added as a parent category'))
->relationship('parent', 'name', fn (Builder $query) => $query->where('parent_id', null))
->getOptionLabelFromRecordUsing(fn ($record) => $record->name)
->searchable()
->preload(),
])
->createOptionUsing(function ($component, $data, $form) {
$record = $component->getRelationship()->getRelated();
$record->fill($data);
$record->save();

$form->model($record)->saveRelationships();

return $record->global_id;
})
Forms\Components\Select::make('category_id')
->label(__('validation.attributes.category'))
->relationship('category', 'name', fn ($query) => $query->with('parent'))
->getOptionLabelFromRecordUsing(fn ($record) => collect([$record->parent?->name, $record->name])->filter()->join(' - '))
->required()
->searchable()
->preload()
->createOptionForm([
Forms\Components\TextInput::make('name')
->label(__('validation.attributes.name'))
->autocomplete(false)
->required()
->rule(fn ($livewire) => UniqueJsonRule::for(table: 'shop_categories', column: 'name', locale: $livewire->activeLocale)),
Forms\Components\Select::make('parent_id')
->label(__('validation.attributes.parent_category'))
->placeholder(__('Leave it empty to be added as a parent category'))
->relationship('parent', 'name', fn (Builder $query) => $query->where('parent_id', null))
->getOptionLabelFromRecordUsing(fn ($record) => $record->name)
->searchable()
->preload(),
])
->createOptionUsing(function ($component, $data, $form) {
$record = $component->getRelationship()->getRelated();
$record->fill($data);
$record->save();

$form->model($record)->saveRelationships();

return $record->global_id;
})
9 replies
FFilament
Created by MohamedSabil83 on 9/28/2023 in #❓┊help
Is it able to use saveRelationships() in action button?
I have a custom page listed created user. I put an action with following info to create a new user with related branches: Action form()
Forms\Components\Section::make()
->schema([
Forms\Components\TextInput::make('user.name')
->label(__('Name'))
->autocomplete(false)
->required(),
]),

Forms\Components\Group::make()
->schema([
Forms\Components\Toggle::make('manage_restaurant_details')
->label(__('Restaurant Details')),
Forms\Components\Toggle::make('manage_branch')
->label(__('Branches')),
Forms\Components\Toggle::make('manage_order')
->label(__('Orders')),
Forms\Components\Toggle::make('manage_qrcode')
->label(__('QR Builder')),
Forms\Components\Toggle::make('manage_membership')
->label(__('Membership')),
Forms\Components\Toggle::make('manage_menu')
->label(__('Menu')),
Forms\Components\Toggle::make('manage_user')
->label(__('Users')),
]),

Forms\Components\Fieldset::make(__('Branches'))
->schema([
Forms\Components\CheckboxList::make('branches')
->hiddenLabel()
->relationship('branches', 'location')
->getOptionLabelFromRecordUsing(fn ($record) => $record->location)
->model(fn ($context) => match ($context) {
'edit' => null,
default => RestaurantUser::class
})
]),
Forms\Components\Section::make()
->schema([
Forms\Components\TextInput::make('user.name')
->label(__('Name'))
->autocomplete(false)
->required(),
]),

Forms\Components\Group::make()
->schema([
Forms\Components\Toggle::make('manage_restaurant_details')
->label(__('Restaurant Details')),
Forms\Components\Toggle::make('manage_branch')
->label(__('Branches')),
Forms\Components\Toggle::make('manage_order')
->label(__('Orders')),
Forms\Components\Toggle::make('manage_qrcode')
->label(__('QR Builder')),
Forms\Components\Toggle::make('manage_membership')
->label(__('Membership')),
Forms\Components\Toggle::make('manage_menu')
->label(__('Menu')),
Forms\Components\Toggle::make('manage_user')
->label(__('Users')),
]),

Forms\Components\Fieldset::make(__('Branches'))
->schema([
Forms\Components\CheckboxList::make('branches')
->hiddenLabel()
->relationship('branches', 'location')
->getOptionLabelFromRecordUsing(fn ($record) => $record->location)
->model(fn ($context) => match ($context) {
'edit' => null,
default => RestaurantUser::class
})
]),
Action action()
->action(function (array $data): void {
$user = User::create($data['user']);
$user->assignRole('restaurant');

$restaurantUser = auth()->user()->currentRestaurant->restaurantUsers()->make($data);
$restaurantUser->user()->associate($user);
$restaurantUser->save();

$this->form->model($restaurantUser)->saveRelationships(); // How to make this line in Action?
})
->form($this->getFormSchema())
->model(RestaurantUser::class)
->action(function (array $data): void {
$user = User::create($data['user']);
$user->assignRole('restaurant');

$restaurantUser = auth()->user()->currentRestaurant->restaurantUsers()->make($data);
$restaurantUser->user()->associate($user);
$restaurantUser->save();

$this->form->model($restaurantUser)->saveRelationships(); // How to make this line in Action?
})
->form($this->getFormSchema())
->model(RestaurantUser::class)
6 replies
FFilament
Created by MohamedSabil83 on 9/26/2023 in #❓┊help
How to get the values from other repeater items?
To sample represent, let's say we have a Repeater to choose a product from Select. When add a new item, I want to omit all selected options from the new Select. So the user can't select the same value twice
4 replies
FFilament
Created by MohamedSabil83 on 7/13/2023 in #❓┊help
Repeater `defaultItems()` not works
The Repeater displayed empty until pressing the add button. I want to display a specific numbers. As I know it's by setting it like ->defaultItems(2) but not works. Am I missing something?
Forms\Components\Repeater::make('blogs')
->schema([
Forms\Components\TextInput::make('title'),
])
->defaultItems(2),
Forms\Components\Repeater::make('blogs')
->schema([
Forms\Components\TextInput::make('title'),
])
->defaultItems(2),
5 replies
FFilament
Created by MohamedSabil83 on 6/12/2023 in #❓┊help
Anyway to disableCreateAnother in general?
Instead of disable createAnother in every CreatePage, is there a way to do it in general i.e. service provider?
6 replies
FFilament
Created by MohamedSabil83 on 3/22/2023 in #❓┊help
How to ignore save relation when FileUpload is empty?
I have this code:
Forms\Components\Group::make()
->relationship('image')
->schema([
Forms\Components\FileUpload::make('path'),
]),
Forms\Components\Group::make()
->relationship('image')
->schema([
Forms\Components\FileUpload::make('path'),
]),
If FileUpload was empty when saving, its return error cause trying to save the relation. Any way to skip the saving relation when FileUpload empty?
3 replies