How to get Model property from recordSelectOptionsQuery

Hi there, greetings from Isla de Margarita, Venezuela, first question here. I'm using RelationManager in multiple Resources, so, depending of Resource/Model I need to filter recordSelectOptionsQuery for an Attach Action, something like : RelationManager: ->recordSelectOptionsQuery( function (Builder $query) { $allowedTypes = $ownerRecord->allowedRelatedAttachTypes <--------------------- return $query->whereIn('trading_partners.type_id', $allowedTypes ); } ) Model: class _TradingPartner extends Model { ... protected static $allowedRelatedAttachTypes = ['P', 'A']; ... } But I'm unable to get something on this stage, thanks in advance for your help
1 Reply
sistemasjg
sistemasjgOP2y ago
Never mind, searched a little bit on this discord server and found a solution. Managed to do it this way: RelationManager: ->recordSelectOptionsQuery( function (Builder $query, $livewire) { // added $livewire parameter to access ownerRecord if ($livewire->ownerRecord->allowedRelatedAttachTypes){ return $query->whereIn('trading_partners.type_id', $livewire->ownerRecord->allowedRelatedAttachTypes); } return $query; } ) Model: class Student extends _TradingPartner { use HasFactory; protected static $partnerType = 'S'; public $allowedRelatedAttachTypes = ['R']; }

Did you find this page helpful?