LEATHEANX
LEATHEANX
FFilament
Created by LEATHEANX on 5/12/2025 in #❓┊help
How to implement specified action/button in laravel filament forms
What I am trying to do: Im trying to add a calculation button for my recalculate What I did: im trying to make a button for my form that have a recalculate function My issue/the error: it keeps bugging saying that the button is doesnt exist or its filament method/class is undefined
use Filament\Forms\Components\Actions\Action;

Action::make('recalculate_salary')
->label('Recalculate NET Salary')
->icon('heroicon-o-refresh')
->action(function (array $data, callable $set) {
$employeeId = $data['employees_id'];
$basicSalary = $data['BASICSALARY'];
$benefitsTotal = 0;

// Recalculate salary
if ($employeeId) {
$benefitsTotal = EmployeeBenefit::where('employees_id', $employeeId)
->where('STATUS', true)
->sum('AMOUNT');
}

// Calculate new net salary
$netSalary = $basicSalary - $benefitsTotal;
$set('NETSALARY', $netSalary > 0 ? $netSalary : 0);
})
use Filament\Forms\Components\Actions\Action;

Action::make('recalculate_salary')
->label('Recalculate NET Salary')
->icon('heroicon-o-refresh')
->action(function (array $data, callable $set) {
$employeeId = $data['employees_id'];
$basicSalary = $data['BASICSALARY'];
$benefitsTotal = 0;

// Recalculate salary
if ($employeeId) {
$benefitsTotal = EmployeeBenefit::where('employees_id', $employeeId)
->where('STATUS', true)
->sum('AMOUNT');
}

// Calculate new net salary
$netSalary = $basicSalary - $benefitsTotal;
$set('NETSALARY', $netSalary > 0 ? $netSalary : 0);
})
4 replies
FFilament
Created by LEATHEANX on 5/6/2025 in #❓┊help
How to prefill from foreign key address
What I did: im trying to prefill the leaverequest with the employees_id that is associated with the users_id My issue/the error: it wont get the employees_id to be prefilled and to be inserted in the database and it returns a null value instead of getting the proper employee_id for the leaverequest Code Forms\Components\Hidden::make('employees_id') ->default(fn () => Filament::auth()->user()?->employee?->id) ->dehydrated(true) ->required(), in the users model public function employee() { return $this->hasOne(Employee::class, 'users_id'); } In the leave request model public function employee() { return $this->belongsTo(Employee::class); } in the employee model public function user() { return $this->belongsTo(User::class, 'users_id'); } public function leaverequest() { return $this->hasMany(Leaverequest::class, 'employees_id'); } side note: I am a beginner level in coding, as i have no prior knowledge in laravel or PHP
10 replies