/** * Responds to requests to GET /books/create */ public function getCreate() { $formatModel = new \App\Format(); $formats_for_dropdown = $formatModel->getFormatsForDropdown(); # Get all the possible tags so we can include them with checkboxes in the view $tagModel = new \App\Tag(); $tags_for_checkbox = $tagModel->getTagsForCheckboxes(); return view('books.create')->with('formats_for_dropdown', $formats_for_dropdown)->with('tags_for_checkbox', $tags_for_checkbox); }
/** * Responds to requests to GET /books/edit/{$id} */ public function getEdit($id = null) { // get book to edit $book = \App\Book::with('tags')->find($id); $authorModel = new \App\Author(); $authors_for_dropdown = $authorModel->getAuthorsForDropdown(); // get all the tags $tagModel = new \App\Tag(); $tags_for_checkboxes = $tagModel->getTagsForCheckboxes(); //dump($tags_for_checkboxes); // get the tags for this book $tags_for_this_book = []; foreach ($book->tags as $tag) { $tags_for_this_book[] = $tag->name; } //dump($tags_for_this_book); //dump($authors_for_dropdown); if (is_null($book)) { \Session::flash('flash_message', 'Book not found.'); //return redirect('\books'); } return view('books.edit')->with(['book' => $book, 'authors_for_dropdown' => $authors_for_dropdown, 'tags_for_checkboxes' => $tags_for_checkboxes, 'tags_for_this_book' => $tags_for_this_book]); }
/** * 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]); }
/** * Responds to requests to GET /cars/create */ public function getCreate() { # Manufacturer dropdown $manufacturerModel = new \App\Manufacturer(); $manufacturers_for_dropdown = $manufacturerModel->getManufacturersForDropdown(); # Tag checkboxes $tagModel = new \App\Tag(); $tags_for_checkbox = $tagModel->getTagsForCheckboxes(); # Sizes dropdown $sizeModel = new \App\Size(); $sizes_for_dropdown = $sizeModel->getSizesForDropdown(); return view('cars.create')->with('manufacturers_for_dropdown', $manufacturers_for_dropdown)->with('tags_for_checkbox', $tags_for_checkbox)->with('sizes_for_dropdown', $sizes_for_dropdown); }