/** * Responds to requests to GET /submittals/edit/{$id} */ public function getEdit($id = null) { # Get this submittal and eager load its tags $submittal = \Myworkspace\Submittal::with('tags')->find($id); if (is_null($submittal)) { \Session::flash('flash_message', 'Submittal not found.'); return redirect('\\submittals'); } # Get all the possible authors so we can build the authors dropdown in the view $authorModel = new \Myworkspace\Author(); $authors_for_dropdown = $authorModel->getAuthorsForDropdown(); # Get all the possible tags so we can include them with checkboxes in the view $tagModel = new \Myworkspace\Tag(); $tags_for_checkbox = $tagModel->getTagsForCheckboxes(); /* Create a simple array of just the tag names for tags associated with this submittal; will be used in the view to decide which tags should be checked off */ $tags_for_this_submittal = []; foreach ($Submittal->tags as $tag) { $tags_for_this_submittal[] = $tag->name; } return view('submittals.edit')->with(['submittal' => $submittal, 'authors_for_dropdown' => $authors_for_dropdown, 'tags_for_checkbox' => $tags_for_checkbox, 'tags_for_this_submittal' => $tags_for_this_submittal]); }