public function getEditOptions($id) { $material = Material::findBySlugOrIdOrFail($id); $options_empty = []; $options_complete = []; $options = Options::all(); $levels = $material->levels()->get(); $option = Options::where('option', '=', 'level')->first(); if ($levels->count()) { $options_complete['level'] = $option->description; } else { $options_empty['level'] = $option->description; } $language_focuses = $material->languageFocuses()->get(); $option = Options::where('option', '=', 'language_focus')->first(); if ($language_focuses->count()) { $options_complete['language_focus'] = $option->description; } else { $options_empty['language_focus'] = $option->description; } $files = $material->files()->get(); $option = Options::where('option', '=', 'files')->first(); if ($files->count()) { $options_complete['files'] = $option->description; } else { $options_empty['files'] = $option->description; } $activity_uses = $material->activityUses()->get(); $option = Options::where('option', '=', 'activity_use')->first(); if ($activity_uses->count()) { $options_complete['activity_use'] = $option->description; } else { $options_empty['activity_use'] = $option->description; } $pupil_tasks = $material->pupilTasks()->get(); $option = Options::where('option', '=', 'pupil_task')->first(); if ($pupil_tasks->count()) { $options_complete['pupil_task'] = $option->description; } else { $options_empty['pupil_task'] = $option->description; } $categories = $material->categories()->get(); $option = Options::where('option', '=', 'category')->first(); if ($categories->count()) { $options_complete['category'] = $option->description; } else { $options_empty['category'] = $option->description; } $books = $material->book()->get(); $option = Options::where('option', '=', 'book')->first(); if ($books->count()) { $options_complete['book'] = $option->description; } else { $options_empty['book'] = $option->description; } $material = $material->getAttributes(); foreach ($material as $key => $value) { $option = Options::where('option', '=', $key)->first(); if ($value == null) { if ($option) { $options_empty[$option->option] = $option->description; } } else { if ($option) { $options_complete[$option->option] = $option->description; } } } return view('material.edit_options', compact('material', 'options_empty', 'options_complete', 'options')); }