How to make Select field disable to edit but it must send the data.

I have a use case, where there are two parent child dropdown, If I select the item on parent field then the child will auto fill. I want to disable to edit child field but send the data while submit the form.
7 Replies
Dennis Koch
Dennis Koch7mo ago
I think dehydrated(true) does that.
Asmit Nepali
Asmit NepaliOP7mo ago
Select::make('role_id')
->label('Roles')
->relationship('roles', 'title')
->live()
->afterStateUpdated(function (Get $get, Set $set) {
$roles = Role::whereIn('id', $get('role_id'))
->with('permissions')
->get();
$rolesId = $roles->flatMap->permissions->pluck('id');

$set('permission_id', $roles);
})
->searchable()
->preload()
->multiple()
->required(),

Select::make('permission_id')
->label('Permissions')
->relationship('permissions', 'title')
->dehydrated(true)
->required()
->multiple()
->searchable()
->preload(),
Select::make('role_id')
->label('Roles')
->relationship('roles', 'title')
->live()
->afterStateUpdated(function (Get $get, Set $set) {
$roles = Role::whereIn('id', $get('role_id'))
->with('permissions')
->get();
$rolesId = $roles->flatMap->permissions->pluck('id');

$set('permission_id', $roles);
})
->searchable()
->preload()
->multiple()
->required(),

Select::make('permission_id')
->label('Permissions')
->relationship('permissions', 'title')
->dehydrated(true)
->required()
->multiple()
->searchable()
->preload(),
@Dennis Koch Thank you ! for the reply but still Not working
Dennis Koch
Dennis Koch7mo ago
The issue isn't ->disabled() but ->relationship(). Those save automatically and don't include the data.
Asmit Nepali
Asmit NepaliOP7mo ago
How can I achieve my objective?
Aminne
Aminne6mo ago
I got the same problem
Asmit Nepali
Asmit NepaliOP6mo ago
Still not figuring out
Bruno Pereira
Bruno Pereira6mo ago
Why not:
Select::make('permission_id')
->label('Permissions')
->relationship('permissions',
'title',
modifyQueryUsing: function(Builder $query, Callable $get) {
if($get('role_id')) {
//query the role permissions
}
//else empty options

})
->dehydrated(true)
->required()
->multiple()
->searchable()
->preload(),
Select::make('permission_id')
->label('Permissions')
->relationship('permissions',
'title',
modifyQueryUsing: function(Builder $query, Callable $get) {
if($get('role_id')) {
//query the role permissions
}
//else empty options

})
->dehydrated(true)
->required()
->multiple()
->searchable()
->preload(),
Tbh I don't know if the modifyQueryUsing accepts other params other than the Builder $query
Want results from more Discord servers?
Add your server