Multiple Text Inputs From Relationship / Saving To Pivot

Ok modifying this question to use a hasMany/pivot relationship.

I have a model that has a list of questions and belongs to a career

class CareerQuestion extends Model
{
    public function career()
    {
        return $this->belongsTo(Career::class);
    }

    public function applications()
    {
        return $this->belongsToMany(CareerApplication::class, 'applications_questions')
            ->withPivot('answer')
            ->withTimestamps();
    }
}

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class CareerApplication extends Model
{
    public function career()
    {
        return $this->belongsTo(Career::class);
    }

    public function questions()
    {
        return $this->belongsToMany(CareerQuestion::class, 'applications_questions')
            ->withPivot('answer')
            ->withTimestamps();
    }
}


Then I am making a form that will loop through all the questions and give a text input so they can store their answers on the pivot table, I have tried a few different way's however I do not think i am on the right track.

                            Repeater::make('questions')
                                ->relationship('questions')
                                ->schema([
                                    TextInput::make('answer')
                                        ->required(),
                                ])
                                ->itemLabel(fn (array $state): ?string => $state['question'] ?? 'SHOULD NEVER REACH HERE'),

When loading the form the SHOULD NEVER REACH HERE is showing and only 1 evern though there is 4 questions. I am guessing I have the repeater relationship setup wrong ?
Was this page helpful?