How to debug in Filament

Hi guys need a little help , I have a custom resource to select which subjects are going to be taught in a class So i created this checkbox field which loads options depending on which pattern/syllabus was selected
CheckboxList::make('subject_id')
->relationship('subjects', 'name')
->label('Subjects')
->options(function (callable $get) {
$patternId = $get('pattern_id');
if (!$patternId) return [];
return Subject::query()
->where('pattern_id', $patternId)
->pluck('name', 'id');
})
->columns(2)
->disabled(fn($record) => filled($record))
->dehydrated(false) // persisted in Pages using afterCreate/afterSave
->helperText('Selections are saved as StudentClassSubjectMapping rows.')
CheckboxList::make('subject_id')
->relationship('subjects', 'name')
->label('Subjects')
->options(function (callable $get) {
$patternId = $get('pattern_id');
if (!$patternId) return [];
return Subject::query()
->where('pattern_id', $patternId)
->pluck('name', 'id');
})
->columns(2)
->disabled(fn($record) => filled($record))
->dehydrated(false) // persisted in Pages using afterCreate/afterSave
->helperText('Selections are saved as StudentClassSubjectMapping rows.')
But apparently it is not saving the subjects in the pivot table ! I cannot get over it, please send boys. Also my model relations are like StudentClass Model
//fillables ...

//relations
public function subjects()
{
return $this->belongsToMany(
\App\Models\Subject::class,
'student_class_subject_mappings', // pivot table
'student_class_id', // FK to this model
'subject_id' // FK to subjects
)->withTimestamps(); // remove if your pivot doesn't have timestamps
}
//fillables ...

//relations
public function subjects()
{
return $this->belongsToMany(
\App\Models\Subject::class,
'student_class_subject_mappings', // pivot table
'student_class_id', // FK to this model
'subject_id' // FK to subjects
)->withTimestamps(); // remove if your pivot doesn't have timestamps
}
No description
6 Replies
toeknee
toeknee2w ago
If it's not saving I susepct the fillabale maybe empty. But you would tend to debug as normal. You can use Telescope to monitor all requests too and see what data was received to what was saved and so on
Zamion101
Zamion1012w ago
I prefer buggregator with ray, it's really good combo with lots of features, you can even use xhprof to generate flamegraph and call graph and see it in buggregator.
Dennis Koch
Dennis Koch2w ago
Are you using a custom page? Or the default resource pages?
Breaking bad
Breaking badOP2w ago
a default resource page @toeknee @Zamion101 @Dennis Koch , I think i solved it by removing the line
->dehydrated(false)
->dehydrated(false)
! Still I really appriciate your help. It is said that a small silly bug is the most dangerous one Haha. But if any one is going to read in future and wanna debug here are copuple of vanilla tips : 1. Turn on QueryLogger and print what all queries was fired to check if its the case -> any query tried to run and failed so you dont have updated data 2. Ofc USe get state on create or before save methods to print your state data -> this will let you know if the data you filled in wrt to your input elements are there in state data or not 3. IF in 1 you didnt got any insert query , in 2 you got some states , its most likely me case aka dehydrate is fasle
Dennis Koch
Dennis Koch2w ago
Oh yeah. Didn’t realise that one. 🙈 My debugging tip: I usually go through the code with Xdebug
Breaking bad
Breaking badOP4d ago
Thanks for tip , but for me it is like taking a deep in new ocean :p will try it out once i get time xoxo

Did you find this page helpful?