MrPaperbag
MrPaperbag
FFilament
Created by MrPaperbag on 5/8/2025 in #❓┊help
Enable disabled button after creating related item
I have the following action on my resource, and as you can see it is checking if the record has 1 or more rounds connected to it. In the gui the action is displayed above the table where the rounds are displayed via a relationmanager. Can I make this disabled/enabled state change interactive, so I dont have to actually reload the page after adding another round(s)? Any help would be much appreciated. Thank you in advance.
<?php
Actions\Action::make('markAsFinished')
->label('Mark as Finished')
->action(function () {

$this->record->update([
'finished' => true,
'winner_id' => $this->record->rounds()->select('winner_id')->groupBy('winner_id')->orderByRaw('COUNT(*) DESC')->first()->winner_id,
]);
return redirect()->route('filament.dashboard.resources.games.view', ['record' => $this->record->id]);
})
->requiresConfirmation()
->color('success')
->disabled(fn() => $this->record->rounds()->count() === 0);
<?php
Actions\Action::make('markAsFinished')
->label('Mark as Finished')
->action(function () {

$this->record->update([
'finished' => true,
'winner_id' => $this->record->rounds()->select('winner_id')->groupBy('winner_id')->orderByRaw('COUNT(*) DESC')->first()->winner_id,
]);
return redirect()->route('filament.dashboard.resources.games.view', ['record' => $this->record->id]);
})
->requiresConfirmation()
->color('success')
->disabled(fn() => $this->record->rounds()->count() === 0);
1 replies
FFilament
Created by MrPaperbag on 5/7/2025 in #❓┊help
Create related resource with another relationship
I am making an app to record games, rounds per game, and scores per player per round. I now have a GameResource with a RoundsRelationManager. On the Game's Edit page I have a table with the rounds and a button to add a new round. I want to open a modal with a form to create a new round. The modal should have a form with the following fields: - Round number (property of the Round model, must only be visible and is a calculated field) - Points per player (property of the Score model that is connected to the Round) - Winner ID (player ID of the winner, must be calculated upon saving of the Round and Score models, not visible in the dialog) Now I am diving into the possibilities of creating both the Round and Scores using mutate methods and such, but I feel like there must be a better way to do this that utilizes the relationships in between the models. I am new to filament, and I am not sure how to approach this. Some help would be appreciated. Below is the code I have so far, including a database sketch (players are actually the users in this case):
2 replies