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