#laravel #api #httpresponse
Вопрос:
Это и есть ответ https://prnt.sc/12u1h6x Вот в чем логика https://prnt.sc/12u1iv7
Превышена максимальная глубина стека
Комментарии:
1. Добро пожаловать в SO. Пожалуйста, публикуйте весь код и ошибки в виде текста, а не в виде скриншотов.
2. Вам необходимо добавить здесь дополнительную информацию о структуре отношений сущностей, ошибка может указывать, например, на циклическую ссылку во время сериализации.
Ответ №1:
Это вопросы сущности
<?php
namespace AppModelsQuestions;
use AppModelsBrand;
use AppModelsQuestionsChoiceTraitsAttributesQuestionAttribute;
use AppModelsQuestionsChoiceTraitsMethodsQuestionMethod;
use AppModelsQuestionsQuestionLink;
use AppModelsQuestionsChoiceChoice;
use AppModelsQuestionsTraitsExtendedEloquentTrait;
use AppModelsQuestionsTraitsScopesQuestionScope;
use IlluminateDatabaseEloquentModel;
class Question extends Model
{
use QuestionAttribute, QuestionMethod, ExtendedEloquentTrait, QuestionScope;
protected $table = 'questions';
protected $guarded = [];
protected $appends = [
'question_name',
'base_name',
'is_loading',
'is_english',
'is_italian',
'is_german',
'is_bisaya',
'is_filipino',
'translated_question',
'locale_question',
'has_succeeding_questions',
];
public function question_type()
{
return $this->belongsTo(QuestionType::class, 'type');
}
public function question_links()
{
return $this->hasMany(QuestionLink::class, 'question');
}
/**
* The questions that belong to the brand.
*/
public function brand()
{
return $this->belongsToMany(Brand::class, 'brand_questions', 'questions', 'brand');
}
/**
* The questions that belong to the choices.
*/
public function choice()
{
return $this->belongsToMany(Choice::class, 'question_links', 'question', 'choice')->withPivot('succeeding');
}
public function questionnaire_contents()
{
return $this->hasMany(QuestionnaireContent::class, 'question_id');
}
}
и это мой выбор сущности/модели
<?php
namespace AppModelsQuestionsChoice;
use IlluminateDatabaseEloquentModel;
use AppModelsQuestionsChoiceTraitsAttributesChoiceAttribute;
use AppModelsQuestionsChoiceTraitsMethodsChoiceMethod;
use AppModelsQuestionsChoiceTraitsScopesChoiceScope;
use AppModelsQuestionsQuestion;
class Choice extends Model
{
use ChoiceAttribute, ChoiceMethod, ChoiceScope;
protected $table = 'choices';
protected $guarded = [];
protected $appends = [
'choice_name',
'has_translation',
'base_name',
'is_loading',
'is_english',
'is_italian',
'is_german',
'is_bisaya',
'is_filipino',
'on_select_choice_name'
];
public function questionLinks()
{
return $this->hasMany(QuestionLink::class, 'choice');
}
/**
* The choice that belong to the questions.
*/
public function questions()
{
return $this->belongsToMany(Question::class, 'question_links', 'choice', 'question');
}
}