How to use $get and $set in custom page
'the get and set is working only on resource, for custom page it is not working'
3 Replies
->maxValue(function(\Filament\Forms\Get $get){
$vehicleId = $get('vehicle_id');
if (is_null($vehicleId)) {
return null;
} else {
$vehicle = Vehicle::find($vehicleId);
return $vehicle->fuel_tank_capacity;
}
}), i used like this its not working the filament custom pages but its working on the resource
Could you share the whole code please?
Grid::make()
->schema([
Radio::make('yard_type')
->options(function () {
$yard = Master::where('parent_id', config('constants.master.yard_type'))->get()->pluck('display_name', 'display_name');
return $yard;
})->inline()->label('Yard Type')->required()
->afterStateUpdated(function (Set $set) {
$set('trip', null);
$set('mcc_id', null);
$set('vehicle_id', null);
})->reactive(),
]),
Grid::make()
->schema([
Select::make('mcc_id')->required()
->label('MCC')->placeholder('Type MCC Name')->autofocus()->preload()->searchable()->reactive()
->getSearchResultsUsing(fn (string $search) => Mcc::where('name', 'like', "%{$search}%")->pluck('name', 'id'))
->options(function () {
$mcc = Mcc::all();
return $mcc->pluck('name', 'id');
})->visible(function (Get $get) {
return $get('yard_type') == config('constants.yard_type.compost_yard') ? true : false;
}),
]), here is the code which i use get and set between two fields.