public function getAuthorsForDropdown() { $authors = \App\Author::orderby('last_name', 'ASC')->get(); $authors_for_dropdown = []; foreach ($authors as $author) { $authors_for_dropdown[$author->id] = $author->last_name . ', ' . $author->first_name; } return $authors_for_dropdown; }
/** * Responds to requests to GET /books/edit/{$id} */ public function getEdit($id = null) { $book = \App\Book::find($id); $authors = \App\Author::orderby('last_name', 'ASC')->get(); $authors_for_dropdown = []; foreach ($authors as $author) { $authors_for_dropdown[$author->id] = $author->last_name . ', ' . $author->first_name; } #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]); }