How to get relationship value using Get $get unititlity?

Hi, I'm trying to set the value of a field, from a relationship when action clicked. My code looks like this:
Action::make('Name')
->tooltip('Insert accommodation name')
->action(function (Set $set, Get $get, $state) {
$set('seo_title', $get('type.name'));
}),
Action::make('Name')
->tooltip('Insert accommodation name')
->action(function (Set $set, Get $get, $state) {
$set('seo_title', $get('type.name'));
}),
$get('type.name') does not work.
4 Replies
gladjanus43
gladjanus436mo ago
I think I did something like this, but dont know if it is the correct way ... ->action(function (Set $set, Get $get, $state) { $type = Type::find( $get('type'))->value; $set('seo_title', $type); }),
Sanjana
Sanjana6mo ago
Repeater::make('preferred_working_hours') ->label(('neww-app::neww-app.user.input.preferred_working_hours')) ->schema(function ($get) { $preferredDays = PreferredDay::getPreferredDay(); $daySchemas = []; foreach ($preferredDays as $day => $translationKey) { $daySchemas[] = Checkbox::make($day)->inline()->reactive(); $daySchemas[] = Group::make([ Forms\Components\TimePicker::make("starttime$day") ->label(("neww-app::neww-app.user.input.preferred_working_hours.$day.starttime$day")) ->hidden(function ($get) use ($day) { return !$get($day); }), Forms\Components\TimePicker::make("endtime$day") ->label(__("neww-app::neww-app.user.input.preferred_working_hours.$day.endtime$day")) ->hidden(function ($get) use ($day) { return !$get($day); }), ])->columns(2); } return $daySchemas; }) ->addable(function ($get) { return empty($get('preferred_working_hours')); }) ->deletable(false) ->columns(2) ->reorderable(false) ->columnSpanFull() i have to show the item on UI when there is null in this column and wnen i am going to edit the form it give the button to add instaed i want to display the item without add
abrardev99
abrardev996mo ago
I don't want to fetch from model, since the data in the forms and the data in the saved relationship can be different.
gladjanus43
gladjanus436mo ago
What exactly do you want then? In your question you ask about a relationship. Maybe a screenshot would help 🙂