本文整理汇总了PHP中Book::with方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::with方法的具体用法?PHP Book::with怎么用?PHP Book::with使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Book
的用法示例。
在下文中一共展示了Book::with方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: borrowList
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();
}
}
示例2: download
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: search
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: index
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: search
/**
* 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: getBooks
public function getBooks()
{
$booklist1 = Book::with('Chapter')->with('Publisher')->get();
return $booklist1;
}
示例7: getEdit
public function getEdit($id)
{
$book = Book::with('author')->findOrFail($id);
$authors = Author::getIdNamePair();
return View::make('book_edit')->with('book', $book)->with('authors', $authors);
}
示例8: postEdit
/**
* 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.');
}
}
示例9: getIndex
public function getIndex()
{
$books = Book::with('Author')->get();
return View::make('book_list')->with('books', $books);
}
示例10: create_book_without_isbn
public function create_book_without_isbn()
{
$this->assertEquals(new Book('Example', new Author('Test')), Book::with()->name('Example')->author(new Author('Test'))->create());
}