Я хотел бы сохранить значение базы данных в переменной. По какой-то причине это не работает, как ожидалось. Ниже приведен код в контроллере:
public function show(Word $word)
{
//
$curriculum = Curriculum::findOrFail($word->id);
// dd($curriculum->id);
session(['key' => $curriculum->id]);
$knowledge = Knowledge::where('curriculum_id','=', $word->id)->get();
$information = Information::where('curriculum_id','=', $word->id)->get();
$practical = Practical::where('curriculum_id','=',$word->id)->get();
$work = Work::where('curriculum_id','=',$word->id)->get();
$entry = Entry::where('curriculum_id','=',$word->id)->get();
$assessment = Assessment::where('curriculum_id','=',$word->id)->get();
$parts = Part::where('curriculum_id','=',$word->id)->get();
$occupurpose = Occupurpose::where('curriculum_id','=',$word->id)->get();
$occutask = Occutask::where('curriculum_id','=',$word->id)->get();
$taskdetail = Taskdetail::where('curriculum_id','=',$word->id)->get();
$purposekm = Purposekm::where('curriculum_id','=',$word->id)->get();
$guidedtopic = Guidetopic::where('curriculum_id','=',$word->id)->get();
$purposepms = Purposepm::where('curriculum_id','=',$word->id)->get();
$purposewem = Purposewem::where('curriculum_id','=',$word->id)->get();
$guidedpmstopics = Guidedpmstopic::where('curriculum_id','=',$word->id)->get();
$guidedwemstopics = Guidedwemstopic::where('curriculum_id','=',$word->id)->get();
$wordTest = new \PhpOffice\PhpWord\PhpWord();
$newSection = $wordTest->addSection();
$SectionHeading = "SECTION 1: CURRICULUM SUMMARY";
$newSection->addText($SectionHeading);
$topicHeading = "1. Occupational Information";
$newSection->addText($topicHeading);
$subTopic = "1.1 Associated Occupation";
$newSection->addText($subTopic);
$newSection->addText($knowledge->associated_occupation);
$occupationTopic = "1.2 Occupation or Specialisation Addressed by this Curriculum";
$newSection->addText($occupationTopic);
$newSection->addText($knowledge->specialisation);
$alternativeTopic = "1.3 Alternative Titles used by Industry";
$newSection->addText($alternativeTopic);
$newSection->addText($knowledge->alternative_title);
$objectWriter = \PhpOffice\PhpWord\IOFactory::createWriter($wordTest,'Word2007');
try {
$objectWriter->save(storage_path('TestWordFile.docx'));
} catch(Exception $e) {
}
return response()->download(storage_path('TestWordFile.docx'));
}
Когда я делаю dd идентификатора учебного плана и результата знания, я получаю правильную обратную связь. Теперь я хотел бы хранить столбец
associated_occupation
в переменную с именем newSection, но я получаю ошибку, упомянутую по теме. Я тоже пробовал
$newSection->addText($knowledge->select('associated_occupation'));
вместо $newSection->addText($knowledge->associated_occupation);
Пожалуйста, помогите.