本文整理汇总了PHP中app\Book::whereHas方法的典型用法代码示例。如果您正苦于以下问题:PHP Book::whereHas方法的具体用法?PHP Book::whereHas怎么用?PHP Book::whereHas使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Book
的用法示例。
在下文中一共展示了Book::whereHas方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: show
public function show($categoryName)
{
$books = Book::whereHas('category', function ($q) use($categoryName) {
$q->where('name', 'like', $categoryName);
})->orderBy('book_added_at', 'desc')->paginate(config('library.posts_per_page'));
$imagePath = \Config::get('library.uploads.webpath');
$imageCoverName = \Config::get('library.uploads.cover_name');
$deffaultImage = \Config::get('library.uploads.deffault_image');
return view('allBook', compact('books', 'imagePath', 'imageCoverName', 'deffaultImage'));
}
示例2: show
/**
* Display the specified resource.
*
* @param int $id
* @return \Illuminate\Http\Response
*/
public function show($name)
{
// $posts = Post::whereHas('comments', function ($query) {
// $query->where('content', 'like', 'foo%');
//})->get();
$books = Book::whereHas('authors', function ($q) use($name) {
$q->where('name', 'like', $name);
})->orderBy('book_added_at', 'desc')->paginate(config('library.posts_per_page'));
$imagePath = \Config::get('library.uploads.webpath');
$imageCoverName = \Config::get('library.uploads.cover_name');
$deffaultImage = \Config::get('library.uploads.deffault_image');
return view('allBook', compact('books', 'imagePath', 'imageCoverName', 'deffaultImage'));
}
示例3: getOverdue
/**
* Return all overdue books of this user
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo
*/
public function getOverdue()
{
return Book::whereHas('transact', function ($query) {
$query->where('type', 'loan')->where('expires', '<=', Carbon::now())->where('user_id', $this->attributes['id']);
})->get();
}
示例4: reserved
/**
* Get library wide reserved books
* @return Book collection
*/
public static function reserved()
{
return Book::whereHas('transact', function ($query) {
$query->where('type', 'reservation');
})->get();
}