Trauma Zombie
Trauma Zombie
Explore posts from servers
FFilament
Created by Trauma Zombie on 2/12/2025 in #❓┊help
How to create form with Filament styles outside the panel?
I try it like this:
class RegistrationForm extends SimplePage implements HasForms
{
use InteractsWithForms;

protected static string $view = 'filament.pages.registration-form';

public ?array $data = [];

public function mount(): void
{
$this->form->fill();
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('first_name')
->required()
->maxLength(255),

TextInput::make('last_name')
->required()
->maxLength(255),
])
->columns(6)
->statePath('data');
}

public function create(): void
{
dd($this->form->getState());
}
}
class RegistrationForm extends SimplePage implements HasForms
{
use InteractsWithForms;

protected static string $view = 'filament.pages.registration-form';

public ?array $data = [];

public function mount(): void
{
$this->form->fill();
}

public function form(Form $form): Form
{
return $form
->schema([
TextInput::make('first_name')
->required()
->maxLength(255),

TextInput::make('last_name')
->required()
->maxLength(255),
])
->columns(6)
->statePath('data');
}

public function create(): void
{
dd($this->form->getState());
}
}
Is it good approach?
7 replies
FFilament
Created by Trauma Zombie on 2/12/2025 in #❓┊help
How to create form with Filament styles outside the panel?
Should I create new layout like this: https://filamentphp.com/docs/3.x/forms/installation#configuring-your-layout or there is a better easier way?
7 replies
FFilament
Created by Trauma Zombie on 12/2/2024 in #❓┊help
How to disable global search for resource?
Yeah, I just need to pass empty array to searchable attributes and it will disable global search. Thank you Leandro. 🙂
11 replies
FFilament
Created by Trauma Zombie on 12/2/2024 in #❓┊help
How to disable global search for resource?
Oh, I figured out. I had defined getGloballySearchableAttributes.
11 replies
FFilament
Created by Trauma Zombie on 12/2/2024 in #❓┊help
How to disable global search for resource?
I tried php artisan filament:optimize-clear, but still got results from global search.
11 replies
FFilament
Created by Trauma Zombie on 12/2/2024 in #❓┊help
How to disable global search for resource?
I was thinking that, but I can still search for users. Maybe something I defined at bottom of my snippet?
11 replies
FFilament
Created by Trauma Zombie on 12/2/2024 in #❓┊help
How to disable global search for resource?
Yeah, sorry, it was too long. I deleted form method.
11 replies
FFilament
Created by Trauma Zombie on 12/2/2024 in #❓┊help
How to disable global search for resource?
class UserResource extends Resource
{
protected static ?string $model = User::class;

protected static ?string $navigationIcon = 'heroicon-o-users';

protected static ?int $navigationSort = 1;

public static function getRecordTitleAttribute(): ?string
{
return null;
}

public static function getModelLabel(): string
{
return 'Používateľ';
}

public static function getPluralModelLabel(): string
{
return 'Používatelia';
}

public static function getNavigationLabel(): string
{
return 'Používatelia';
}

public static function getNavigationGroup(): ?string
{
return 'Administrácia';
}

public static function getNavigationParentItem(): ?string
{
return null;
}

public static function getNavigationBadge(): ?string
{
return null;
}

public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'view' => Pages\ViewUser::route('/{record}'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}

/** @return Builder<User> */
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery();
}

/** @param User $record */
public static function getGlobalSearchResultTitle(Model $record): string
{
return $record->name;
}

public static function getGloballySearchableAttributes(): array
{
return ['name', 'email'];
}

/** @param User $record */
public static function getGlobalSearchResultDetails(Model $record): array
{
return [
'Email' => $record->email,
];
}

/** @return Builder<User> */
public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery();
}
}
class UserResource extends Resource
{
protected static ?string $model = User::class;

protected static ?string $navigationIcon = 'heroicon-o-users';

protected static ?int $navigationSort = 1;

public static function getRecordTitleAttribute(): ?string
{
return null;
}

public static function getModelLabel(): string
{
return 'Používateľ';
}

public static function getPluralModelLabel(): string
{
return 'Používatelia';
}

public static function getNavigationLabel(): string
{
return 'Používatelia';
}

public static function getNavigationGroup(): ?string
{
return 'Administrácia';
}

public static function getNavigationParentItem(): ?string
{
return null;
}

public static function getNavigationBadge(): ?string
{
return null;
}

public static function getPages(): array
{
return [
'index' => Pages\ListUsers::route('/'),
'create' => Pages\CreateUser::route('/create'),
'view' => Pages\ViewUser::route('/{record}'),
'edit' => Pages\EditUser::route('/{record}/edit'),
];
}

/** @return Builder<User> */
public static function getEloquentQuery(): Builder
{
return parent::getEloquentQuery();
}

/** @param User $record */
public static function getGlobalSearchResultTitle(Model $record): string
{
return $record->name;
}

public static function getGloballySearchableAttributes(): array
{
return ['name', 'email'];
}

/** @param User $record */
public static function getGlobalSearchResultDetails(Model $record): array
{
return [
'Email' => $record->email,
];
}

/** @return Builder<User> */
public static function getGlobalSearchEloquentQuery(): Builder
{
return parent::getGlobalSearchEloquentQuery();
}
}
11 replies
FFilament
Created by Trauma Zombie on 11/5/2024 in #❓┊help
How to validate Select relation field?
Thank you, this is what I was looking for. 🙂
7 replies
FFilament
Created by Trauma Zombie on 11/5/2024 in #❓┊help
How to validate Select relation field?
Hey, thank you, but still not working.
7 replies
FFilament
Created by Trauma Zombie on 7/15/2024 in #❓┊help
How to refresh relation manager on action?
This is my action:
Action::make('recalculateCommissions')
->label('Recalculate commissions')
->icon('heroicon-o-calculator')
->beforeFormFilled(function (Contract $record, Action $action): void {
$canDelete = $record->commissions->every(function (Commission $commission): bool {
return is_null($commission->invoice_id) && is_null($commission->paid_at);
});

if (! $canDelete) {
Notification::make()
->title('It is not possible to recalculate commissions')
->body('There are already invoices or payments for some commissions. It is not possible to recalculate commissions.')
->warning()
->persistent()
->send();

$action->halt();
}
})
->form([
MoneyInput::make('total_commission')
->label('Total commission')
->default(fn (Contract $record): ?float => $record->total_commission)
->required()
->minValue(0),
])
->modalWidth(MaxWidth::Medium)
->modalSubmitActionLabel('Recalculate')
->modalDescription('All commissions of this contract will be deleted and recalculated.')
->action(function (Contract $record, array $data): void {
$record->update([
'total_commission' => $data['total_commission'],
]);

(new RecalculateCommissions())->execute($record);

Notification::make()
->title('Commissions recalculated')
->body('Commissions have been recalculated successfully.')
->success()
->send();
})
->visible(auth()->user()->hasRole(UserRole::Administrator));
Action::make('recalculateCommissions')
->label('Recalculate commissions')
->icon('heroicon-o-calculator')
->beforeFormFilled(function (Contract $record, Action $action): void {
$canDelete = $record->commissions->every(function (Commission $commission): bool {
return is_null($commission->invoice_id) && is_null($commission->paid_at);
});

if (! $canDelete) {
Notification::make()
->title('It is not possible to recalculate commissions')
->body('There are already invoices or payments for some commissions. It is not possible to recalculate commissions.')
->warning()
->persistent()
->send();

$action->halt();
}
})
->form([
MoneyInput::make('total_commission')
->label('Total commission')
->default(fn (Contract $record): ?float => $record->total_commission)
->required()
->minValue(0),
])
->modalWidth(MaxWidth::Medium)
->modalSubmitActionLabel('Recalculate')
->modalDescription('All commissions of this contract will be deleted and recalculated.')
->action(function (Contract $record, array $data): void {
$record->update([
'total_commission' => $data['total_commission'],
]);

(new RecalculateCommissions())->execute($record);

Notification::make()
->title('Commissions recalculated')
->body('Commissions have been recalculated successfully.')
->success()
->send();
})
->visible(auth()->user()->hasRole(UserRole::Administrator));
2 replies
FFilament
Created by Trauma Zombie on 7/9/2024 in #❓┊help
How to close notification slide-over on action
Sorry for late reply, thank you for your interest. For me it is not closing only in SPA mode. When I disabled it, it is working just fine.
16 replies
FFilament
Created by Trauma Zombie on 7/9/2024 in #❓┊help
How to close notification slide-over on action
Still looking for the solution, if anyone has it.
16 replies
FFilament
Created by Trauma Zombie on 6/12/2024 in #❓┊help
Loading wrong model on infolist
When I remove ->orWhere('id', auth()->id()), part it works just fine, but I want to include auth user inside this query.
2 replies
FFilament
Created by Trauma Zombie on 5/30/2024 in #❓┊help
Where to send notification after relationship created
Good idea. I keep forgetting about this option. Thank you, Dan!
3 replies
FFilament
Created by Trauma Zombie on 5/14/2024 in #❓┊help
How to correctly typehint or set return types for IDE support and autocomplete?
Yeah, I know, but there is too many components that I want to use this. For example TextEntry, TextInput, Select, Toggle, Textarea, TextRich etc. I dont want to duplicate it.
4 replies
FFilament
Created by Trauma Zombie on 5/13/2024 in #❓┊help
How to disable toggables on table?
public function table(Table $table): Table
{
return parent::table($table)
->columns(DiagnosisTable::getColumns())
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->searchable(false) // working
->toggleable(false); // not working
}
public function table(Table $table): Table
{
return parent::table($table)
->columns(DiagnosisTable::getColumns())
->filters([
//
])
->actions([
Tables\Actions\ViewAction::make(),
Tables\Actions\EditAction::make(),
])
->bulkActions([
Tables\Actions\BulkActionGroup::make([
Tables\Actions\DeleteBulkAction::make(),
]),
])
->searchable(false) // working
->toggleable(false); // not working
}
I extract all columns to separete class and method, so I can reuse it and I dont need to duplicate my code.
7 replies
FFilament
Created by Trauma Zombie on 4/23/2024 in #❓┊help
Notify user assigned or detached using Select
I want to send it after form is submitted. This is probably Laravel problem. For example, when I already have Task, and someone edited it, adds new user via that Select field, I want to send notification to that new user.
4 replies
FFilament
Created by Trauma Zombie on 3/27/2024 in #❓┊help
Relationship not saved when using createOptionUsing on Select input
I updated that method to this:
->createOptionUsing(function (Select $component, array $data, Form $form, Forms\Get $get): int {
$record = $component->getRelationship()->getRelated();
$record->fill([
...$data,
'broker_id' => User::find($get('broker_id'))->id ?? auth()->id(),
]);
$record->save();

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

return $record->getKey();
}),
->createOptionUsing(function (Select $component, array $data, Form $form, Forms\Get $get): int {
$record = $component->getRelationship()->getRelated();
$record->fill([
...$data,
'broker_id' => User::find($get('broker_id'))->id ?? auth()->id(),
]);
$record->save();

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

return $record->getKey();
}),
2 replies
FFilament
Created by Trauma Zombie on 3/20/2024 in #❓┊help
How to set value to createOptionForm from another field?
I found this method that fixed my problem:
->createOptionUsing(function (array $data, Forms\Get $get): int {
$user = User::find($get('broker_id')) ?? auth()->user();

return $user->subjects()->create($data)->getKey();
}),
->createOptionUsing(function (array $data, Forms\Get $get): int {
$user = User::find($get('broker_id')) ?? auth()->user();

return $user->subjects()->create($data)->getKey();
}),
2 replies