Select field hasMany relation
Hello all, I am trying to achieve a select field relation with a hasMany relation.
I have one Model called
in Content.php I have relations defined as;
also in ContentVisibility.php as;
I want to Make two select fields in "EditContent" resource which edits the relations.
I came up like these;
But as far as I understand "relationship" for select searches for a
Did I missed something?
Thanks.
I have one Model called
Content and one model ContentVisibilityContentVisibility holds a content_id, with a type field which can be either be BRANCH or COMMUNITYin Content.php I have relations defined as;
public function visibilities(): HasMany {
return $this->hasMany(ContentVisibility::class, 'content_id', 'id');
}also in ContentVisibility.php as;
public function content(): BelongsTo {
return $this->belongsTo(Content::class, 'id', 'content_id');
}I want to Make two select fields in "EditContent" resource which edits the relations.
I came up like these;
Select::make('branch_visibility_id')
->label('Show only to this branches...')
->multiple()
->options( ... )
->relationship('visibilities', fn (Builder $query) => $query->where('type', ContentVisibilityTypeEnum::BRANCH))
->searchable(),
Select::make('community_visibilities')
->label('Show only to this communities...')
->multiple()
->options(...)
->relationship('visibilities', fn (Builder $query) => $query->where('type', ContentVisibilityTypeEnum::COMMUNITY))
->searchable(),But as far as I understand "relationship" for select searches for a
BelongsToMany relation, which I think it is not suitable for this situation.Did I missed something?
Thanks.