public static function editBook($data, $id) { $book = Book::find($id); if ($data['title'] != '') { $book->title = $data['title']; } if ($data['isbn10'] != '') { $book->isbn10 = $data['isbn10']; } $author = new Author(); $genre = new Genre(); $author->name = $data['author']; $genre->name = $data['genre']; $authorToRemove = Author::find($data['authors']); $genreToRemove = Genre::find($data['genres']); $exisitngAuthor = Author::find($data['existing-author']); $exisitngGenre = Genre::find($data['existing-genre']); $book->authors()->detach($authorToRemove['author_id']); $book->genres()->detach($genreToRemove['genre_id']); $book->authors()->attach($exisitngAuthor['author_id']); $book->genres()->attach($exisitngGenre['genre_id']); if ($data['author'] != '') { $book->authors()->save($author); var_dump($data['author']); } if ($data['genre'] != '') { $book->genres()->save($genre); } $book->save(); }
public function show($id) { $genre = Genre::find($id); $books = Book::where('genre_id', '=', $id)->get(); $data = array('genre' => $genre, 'books' => $books); return view('pages.genre')->with('data', $data); }
public function removeGenre(Request $request) { $genre = Genre::find($request->get('id')); $genre->delete(); return redirect()->back(); }
public function show($genre_id, $id) { $book = Book::join('genre', 'genre.id', '=', 'book.genre_id')->join('author', 'author.id', '=', 'book.author_id')->join('publisher', 'publisher.id', '=', 'book.publisher_id')->select('book.id', 'title', 'genre_id', 'genre.name as genre_name', 'author_id', 'author.name as author_name', 'publisher_id', 'publisher.name as publisher_name', 'image', 'isbn', 'description_short', 'book.description', 'price', 'sale', 'quantity')->findOrFail($id); if ($genre_id != 'genre') { $genre = Genre::find($genre_id); if ($genre->count() > 0) { return view('pages.book')->with('book', $book)->with('genre', $genre); } else { return view('errors.404'); } } else { return view('pages.book')->with('book', $book); } }
public static function editGenre($data, $id) { $genre = Genre::find($id); $genre->name = $data['title']; $genre->save(); }
public function find(Route $route) { $this->genre = Genre::find($route->getParameter('genero')); }
/** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { $genre = Genre::find($id); $genre->delete(); return Redirect('/genres'); }