whimsical_pomelo_17483
whimsical_pomelo_17483
FFilament
Created by whimsical_pomelo_17483 on 8/25/2023 in #❓┊help
attach form
Hi I'd like to customize the attach select that is shown when i attach a resource to a course. The model to attach to has a relation to a related table (like a category of the resource).
Table **COURSE**
...

Table **COURSE_RESOURCE**
course_id
resource_id

Table **RESOURCE**
resource_name
resource_type_id
....

Table **RESOURCE_TYPE**
resource_type
Table **COURSE**
...

Table **COURSE_RESOURCE**
course_id
resource_id

Table **RESOURCE**
resource_name
resource_type_id
....

Table **RESOURCE_TYPE**
resource_type
When attaching a resource to a course with the relationManager, i'd like to be able to use the select to filter on both the resource_name AND the resource_type. I try this (where resourceType is the eloquent model relation belongsTo between the 2 tables resource && resource_type)
AttachAction::make()
->recordSelectSearchColumns(['resource_name', 'resourceType.resource_type'])
AttachAction::make()
->recordSelectSearchColumns(['resource_name', 'resourceType.resource_type'])
but i doesn't work, it does not make the join in the query. An other way would be to present a full table of the model to attach to instead of just the select. Is there a way to setup the attach form to show a full table of resource (with related resource_type column) with filter so that you can select any row to attach to (after eventualy filtering) ? Any idea ?
4 replies
FFilament
Created by whimsical_pomelo_17483 on 8/24/2023 in #❓┊help
BelongsToMany relation issue
Hi I have issue to setup the relationManager for belongsToMany relations with pivot table. I have 2 tables and a pivot table with ID & TABLE1_ID et TABLE2_ID. Both eloquent model have the related relation set with the return belongsToMany to the other table. I have created a php artisan make:filament-relation-manager and add the class in the getRelations() methods. On the frontend in the edit form of TABLE1, the HTML table listing all the rows from the PIVOT table is showing nicely. If i change directly in mySql a TABLE2_ID in a row of the pivot table, it reflects fine on the html table after refresh, nice ! Now the issue : When using the create button, it show a form a when i save the data, it crashes because it tries to insert in the TABLE2 table without some required field. It shows only a CREATE button on the related HTML table, no ATTACH. I do not want to have the possibility to add directly a TABLE2 row from this form, i have a separate resource for managing TABLE2. I only want to be able to add / edit a row of the PIVOT table and some extra columns beside the 2 IDs in this table. Any idea on what to check ? Thx !
6 replies