F
Filamentβ€’14mo ago
Chriis

Filling records from a table into a Select input when the resource have no direct relationship

Hi, like the title say, I have a Resource and in the creation form I want to have a select which contains another resource records. The problem is these resources have zero direct relationship. How can I achieve that ?
16 Replies
awcodes
awcodesβ€’14mo ago
->options(fn () => OtherModel::get()->pluck('name', 'id')->toArray)
Chriis
ChriisOPβ€’14mo ago
Ok thanks Also, can I call a relationship of this Model ? Even if I'm in another Resource/Model ?
Chriis
ChriisOPβ€’14mo ago
This is the schema, the creation form I'm talking about is the Sheet one. In this form I have a select which is filled with every competency_framework record, and depending on this select result, I display another select (multiple this time) with every competencies of this competency_framework
No description
krekas
krekasβ€’14mo ago
So does your model has relation or not? Use said it doesn't but in the screen it has belongstomany
Chriis
ChriisOPβ€’14mo ago
Yes the Sheet Resource has 0 relation with the CompetencyFramework one πŸ™‚ However, competency framework intervenes in the Sheet creation form only for filtering the competencies (in relation n-n with sheet)
krekas
krekasβ€’14mo ago
If I understand correctly you want this
Chriis
ChriisOPβ€’14mo ago
Yes, I looked at this example multiple times but the fact that the data is hardcoded make the comprehension a little bit more difficult
krekas
krekasβ€’14mo ago
Replace hard-coded data with your own
Chriis
ChriisOPβ€’14mo ago
No description
krekas
krekasβ€’14mo ago
Should work
Chriis
ChriisOPβ€’14mo ago
(its the doc btw) Yes, but could you explain to me the options() line of 'sub_category', pls I don't understand the Collection => ...
krekas
krekasβ€’14mo ago
It's a return type A php thing
Chriis
ChriisOPβ€’14mo ago
Well yes but πŸ˜… You know what, I'm going to figure that out xD Its the arrow function syntax that got me confused I think, my bad
krekas
krekasβ€’14mo ago
Arrow is just shorter version of function () { return ... }
Chriis
ChriisOPβ€’14mo ago
Yep I've done a quick reminder on that πŸ˜‰
Want results from more Discord servers?
Add your server