Dynamically change Form component in Repeater

Just want to say that I'm not an expert in php or laravel or filament. Basically I'm doing a quiz, and I'm facing this issue where I want some of the questions to be toggle or just a textInput, this is my current code inside repeater (only the schema):
->schema(function ($record) {

$userCargoFormulario = DB::table('user_cargo_formulario as ucf')
->join('cargo_formulario as cf','ucf.cargo_formulario_id','=','cf.id')
->where('ucf.user_id', auth()->id())->get('tipo_id')->toArray();

// dd($userCargoFormulario);

if($userCargoFormulario[0]->tipo_id == 3){
return TextInput::make('resposta');
}
})
->schema(function ($record) {

$userCargoFormulario = DB::table('user_cargo_formulario as ucf')
->join('cargo_formulario as cf','ucf.cargo_formulario_id','=','cf.id')
->where('ucf.user_id', auth()->id())->get('tipo_id')->toArray();

// dd($userCargoFormulario);

if($userCargoFormulario[0]->tipo_id == 3){
return TextInput::make('resposta');
}
})


another example is that if(tipo_id == 3) should return toggle::make('resposta') but this is the error returned:
4 Replies
hosmar27
hosmar27OP4mo ago
No description
Antea
Antea4mo ago
It needs an array of components instead of returning just TextInput
hosmar27
hosmar27OP4mo ago
I searched for it and found nothing, could you explain to me how to do it?
Antea
Antea4mo ago
->schema(function ($record) {

$userCargoFormulario = DB::table('user_cargo_formulario as ucf')
->join('cargo_formulario as cf','ucf.cargo_formulario_id','=','cf.id')
->where('ucf.user_id', auth()->id())->get('tipo_id')->toArray();

// dd($userCargoFormulario);

if($userCargoFormulario[0]->tipo_id == 3){
return [ TextInput::make('resposta')] ; //change to array here
}
})
->schema(function ($record) {

$userCargoFormulario = DB::table('user_cargo_formulario as ucf')
->join('cargo_formulario as cf','ucf.cargo_formulario_id','=','cf.id')
->where('ucf.user_id', auth()->id())->get('tipo_id')->toArray();

// dd($userCargoFormulario);

if($userCargoFormulario[0]->tipo_id == 3){
return [ TextInput::make('resposta')] ; //change to array here
}
})
Want results from more Discord servers?
Add your server