Filament6mo ago

HasMany relationship by only using where clause (for RelationManager)

My problem is: Is it possible to create a relationship in Eloquent (because RelationManager requires a relationship) without using a foreign key? I don't have a role_id column in my permissions table, so the relationship would be based on a where like condition, but I don't think that's possible using Eloquent. Context: I have a few classes: Solicitation, SolicitationStage, Role and Permission. Role and Permission are from Spatie Permissions package. Solicitation and SolicitationStage are classes of mine. Each Solicitation can have many stages (SolicitationStage; see attachment 2), so I created a Resource to manage every config related to a Solicitation, including its stages. Not every user can see (by see I mean in another resource) every stage of a solicitation, so the admin has to assign which roles can see which stages (would be something like the FIlament Shield default resource (see attachment 1)). So we end up having a few permissions related to the Solicitation class itself (if the user can create, edit and delete stages) and some to the SolicitationStage (if the user can see the stage). I know I could create a pivot table to make this relationship, but the reason I don't want to create a pivot table is because I already have permissions related to the Solicitation that are not using a pivot table (Filament Shield), so having some permissions using a pivot table and some don't would be a little weird.
No description
No description
0 Replies
No replies yetBe the first to reply to this messageJoin