Trauma Zombie
Trauma Zombie
Explore posts from servers
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
NNuxt
Created by Trauma Zombie on 10/14/2024 in #❓・help
SOLVED: How to get full URL including domain?
Oh, I really missed this one. Thank you.
4 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
FFilament
Created by Trauma Zombie on 3/6/2024 in #❓┊help
Nested relation form
Can you try it with just belongsTo relations? I am not sure if it matters, but maybe like this:
<?php

class Country extends Model
{
//
}

class City extends Model
{
public function district(): BelongsTo
{
return $this->belongsTo(District::class);
}
}

class District extends Model
{
public function country(): BelongsTo
{
return $this->belongsTo(Country::class);
}
}

class CityResource extends Resource
{
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->required(),

Section::make("District")
->relationship('district')
->schema([
TextInput::make("name")->required(),

Section::make("Country")
->relationship("country")
->schema([
TextInput::make("name")->required(),
])
])
]);
}
}
<?php

class Country extends Model
{
//
}

class City extends Model
{
public function district(): BelongsTo
{
return $this->belongsTo(District::class);
}
}

class District extends Model
{
public function country(): BelongsTo
{
return $this->belongsTo(Country::class);
}
}

class CityResource extends Resource
{
public static function form(Form $form): Form
{
return $form
->schema([
TextInput::make('name')
->required(),

Section::make("District")
->relationship('district')
->schema([
TextInput::make("name")->required(),

Section::make("Country")
->relationship("country")
->schema([
TextInput::make("name")->required(),
])
])
]);
}
}
19 replies
FFilament
Created by Trauma Zombie on 3/6/2024 in #❓┊help
Nested relation form
Right!
19 replies
FFilament
Created by Trauma Zombie on 3/6/2024 in #❓┊help
Nested relation form
I have nested relation like this:
class ClientResource extends Resource
{
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make()
->relationship('entity')
->schema([
// Fields on the entity model

Forms\Components\Section::make()
->relationship('address')
->schema([
// Fields on the address model
])
]),
]);
}
}
class ClientResource extends Resource
{
public static function form(Form $form): Form
{
return $form
->schema([
Forms\Components\Section::make()
->relationship('entity')
->schema([
// Fields on the entity model

Forms\Components\Section::make()
->relationship('address')
->schema([
// Fields on the address model
])
]),
]);
}
}
19 replies
FFilament
Created by Trauma Zombie on 3/6/2024 in #❓┊help
Nested relation form
In my example Client belongsTo Entity that belongsTo Address, but when I am creating new client, it is created, also entity is created, but address not. When I edit that client and fill out also address fields, it is created now (only on edit).
19 replies
FFilament
Created by Trauma Zombie on 3/6/2024 in #❓┊help
Nested relation form
So, the code I posted above should work, and if it doesn't, is the problem somewhere on my end?
19 replies
FFilament
Created by Trauma Zombie on 3/6/2024 in #❓┊help
Reusable sections
27 replies
FFilament
Created by Trauma Zombie on 3/6/2024 in #❓┊help
Reusable sections
If you still have a moment, you could take a look at my other problem I'm having.
27 replies