how can we get data into select form, from 2 relations.
i have a select form,
where i want to show names of users of the current project members and the client can Comment/message or talk with each other.
so i want a data to select form where i want to show the current project members and client names
currently i am using this where i am able to get project members names but not client name how can i get both data into one Select form.
here i my current code
Forms\Components\Select::make('user_id') ->options(ProjectMember::where('project_id', '=', $this->ownerRecord->id)->pluck('freelancer_id', 'freelancer_id'))->searchable()->required() ->required()->columnSpanFull(),here freelancer is user/projectMember so how can i get client name there and as well as i want to show freelancer.user.name not freelancer_id. thank you in advance.
5 Replies
Hi @D E V , can u please provide the result of that code? and edit the display with inspect element, edit your select form so we can understand what kind of result you want, because, for me, i dont really get what you want. thankyou mate.
Looks like he needs to get a label from a distant relation. So from the Project he has a BelongsToMany relation to Member, which has a BelongsTo relation to User. He wants to show a Select of members, but use the related user name as the label. I can't provide any code atm to help as I'm on my phone.
ok ,So here it is the result here is project resources view ok and i have a comment section. in image
and i want that
here is my comment resource relation manager
here is my comment resource relation manager
class CommentsRelationManager extends RelationManager { protected static string $relationship = 'comments'; public function form(Form $form): Form { return $form ->schema([ Forms\Components\Select::make('user_id') ->options(ProjectMember::where('project_id', '=', $this->ownerRecord->id)->pluck('freelancer_id', 'freelancer_id'))->searchable()->required() ->required()->columnSpanFull(), RichEditor::make('comment') ->required() ->maxLength(1000) ->columnSpanFull(), Forms\Components\Toggle::make('is_private') ->required(), ]); } public function table(Table $table): Table { return $table ->columns([ Tables\Columns\TextColumn::make('user.name') ->sortable()->searchable(), Tables\Columns\TextColumn::make('comment') ->limit(55)->sortable()->searchable(), Tables\Columns\IconColumn::make('is_private') ->boolean(), Tables\Columns\TextColumn::make('created_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), Tables\Columns\TextColumn::make('updated_at') ->dateTime() ->sortable() ->toggleable(isToggledHiddenByDefault: true), ]) ....................................i want to show client name and all project members name in select form at a time how can i do that
I'm not downloading random files with no extension. As per #✅┊rules, please provide any supporting code in a gist.
So is freelancer_id a foreign key to the User table?
And you have a relationship called user() on your Comment model?
i am sorry i don't know how to shere image in a good way.
Thank you so much
i solved it.