Fail to attach questions to quiz.

quiz_questions is a pivot table where it stores quiz_id and question_id. right now i have a QuestionRelationManager under the Quiz resource. Quiz.php
public function questions()
{
return $this->hasMany(config('laravel-quiz.models.quiz_question'));
}
public function questions()
{
return $this->hasMany(config('laravel-quiz.models.quiz_question'));
}
Question.php
public function quiz_questions()
{
return $this->hasMany(config('laravel-quiz.models.quiz_question'));
}
public function quiz_questions()
{
return $this->hasMany(config('laravel-quiz.models.quiz_question'));
}
QuizQuestion.php
public function question()
{
return $this->belongsTo(config('laravel-quiz.models.question'));
}
public function question()
{
return $this->belongsTo(config('laravel-quiz.models.question'));
}
QuestionsRelationManager.php
protected static string $relationship = 'questions';

Tables\Actions\AttachAction::make()->form(fn (AttachAction $action): array => [
Forms\Components\Select::make('question_id')
->relationship('question', 'name')
->required(),
]),
protected static string $relationship = 'questions';

Tables\Actions\AttachAction::make()->form(fn (AttachAction $action): array => [
Forms\Components\Select::make('question_id')
->relationship('question', 'name')
->required(),
]),
It does shows the questions, however i cant attach it. The error is

Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::getQualifiedRelatedKeyName()

Call to undefined method Illuminate\Database\Eloquent\Relations\HasMany::getQualifiedRelatedKeyName()
5 Replies
krekas
krekas2y ago
Not related to your question but relation name should be camel case. quizQuestions
black ka1ser
black ka1serOP2y ago
thank you. in your opinion do you think the error comes from the relationship naming?
krekas
krekas2y ago
it's possible
Dennis Koch
Dennis Koch2y ago
Does this setup work without Filament? I don’t think so. Is there more data attached to QuizQuestion. Also this seems to be a full model and not a pivot model. I think you need a BelongsToMany in both directions without that model in between .
black ka1ser
black ka1serOP2y ago
thanks sir, ill try
Want results from more Discord servers?
Add your server