예제 #1
0
 public function borrowList()
 {
     if (Datatable::shouldHandle()) {
         return Datatable::collection(Book::with('author')->orderBy('id', 'desc')->get())->showColumns('id', 'title', 'amount', 'stock')->addColumn('author', function ($model) {
             return $model->author->name;
         })->addColumn('borrow', function ($model) {
             $html = '<a href="' . route('books.borrow', $model->id) . '" class="btn btnn"> <i class="mdi-action-grade"></i> </a>';
             return $html;
         })->searchColumns('title', 'amount', 'author')->orderColumns('title', 'amount', 'author')->make();
     }
 }
 public function download($id)
 {
     $book = Book::with(array('chapter' => function ($query) {
         $query->orderBy('order', 'asc');
     }, 'chapter.element' => function ($query) {
         $query->orderBy('order', 'asc');
     }))->where("id", "=", $id)->get();
     $view = View::make('pdf/result', array("book" => $book));
     $pdf = new TCPDF();
     $pdf->AddPage();
     $pdf->writeHTML($view, true, false, true, false, '');
     $filename = public_path() . '/pdf/test.pdf';
     $pdf->output($filename, 'F');
     return Response::download($filename);
 }
예제 #3
0
 public static function search($query)
 {
     # If there is a query, search the library with that query
     if ($query) {
         # Eager load tags and author
         $books = Book::with('tags', 'author')->whereHas('author', function ($q) use($query) {
             $q->where('name', 'LIKE', "%{$query}%");
         })->orWhereHas('tags', function ($q) use($query) {
             $q->where('name', 'LIKE', "%{$query}%");
         })->orWhere('title', 'LIKE', "%{$query}%")->orWhere('published', 'LIKE', "%{$query}%")->get();
     } else {
         # Eager load tags and author
         $books = Book::with('tags', 'author')->get();
     }
     return $books;
 }
예제 #4
0
 public function index()
 {
     if (Datatable::shouldHandle()) {
         return Datatable::collection(Book::with('author')->orderBy('id', 'desc')->get())->showColumns('id', 'title', 'amount')->addColumn('author', function ($model) {
             return $model->author->name;
         })->addColumn('1', function ($model) {
             $html = '<a href="' . route('admin.books.edit', $model->id) . '" class="btn btnn"> <i class="mdi-editor-mode-edit"></i> </a>';
             return $html;
         })->addColumn('2', function ($model) {
             $html = Form::open(['route' => ['admin.books.destroy', $model->id], 'method' => 'delete']);
             $html .= '<button class="btn btnn" type="submit"> <i class="mdi-action-delete"></i> </button>';
             $html .= Form::close();
             return $html;
         })->searchColumns('title', 'amount', 'author')->orderColumns('title', 'amount', 'author')->make();
     }
     return View::make('books.index')->withTitle('Buku');
 }
예제 #5
0
 /**
  * Search among books, authors and tags
  * @return Collection
  */
 public static function search($query)
 {
     # If there is a query, search the library with that query
     if ($query) {
         # Eager load tags and author
         $books = Book::with('tags', 'author')->whereHas('author', function ($q) use($query) {
             $q->where('name', 'LIKE', "%{$query}%");
         })->orWhereHas('tags', function ($q) use($query) {
             $q->where('name', 'LIKE', "%{$query}%");
         })->orWhere('title', 'LIKE', "%{$query}%")->orWhere('published', 'LIKE', "%{$query}%")->get();
         # Note on what `use` means above:
         # Closures may inherit variables from the parent scope.
         # Any such variables must be passed to the `use` language construct.
     } else {
         # Eager load tags and author
         $books = Book::with('tags', 'author')->get();
     }
     return $books;
 }
예제 #6
0
파일: Book.php 프로젝트: nverdhan/qdbwrite
 public function getBooks()
 {
     $booklist1 = Book::with('Chapter')->with('Publisher')->get();
     return $booklist1;
 }
 public function getEdit($id)
 {
     $book = Book::with('author')->findOrFail($id);
     $authors = Author::getIdNamePair();
     return View::make('book_edit')->with('book', $book)->with('authors', $authors);
 }
 /**
  * Process the "Edit a book form"
  * @return Redirect
  */
 public function postEdit()
 {
     try {
         $book = Book::with('tags')->findOrFail(Input::get('id'));
     } catch (exception $e) {
         return Redirect::to('/book')->with('flash_message', 'Book not found');
     }
     try {
         # http://laravel.com/docs/4.2/eloquent#mass-assignment
         $book->fill(Input::except('tags'));
         $book->save();
         # Update tags associated with this book
         if (!isset($_POST['tags'])) {
             $_POST['tags'] = array();
         }
         $book->updateTags($_POST['tags']);
         return Redirect::action('BookController@getIndex')->with('flash_message', 'Your changes have been saved.');
     } catch (exception $e) {
         return Redirect::to('/book')->with('flash_message', 'Error saving changes.');
     }
 }
 public function getIndex()
 {
     $books = Book::with('Author')->get();
     return View::make('book_list')->with('books', $books);
 }
예제 #10
0
 public function create_book_without_isbn()
 {
     $this->assertEquals(new Book('Example', new Author('Test')), Book::with()->name('Example')->author(new Author('Test'))->create());
 }