我需要让作者搜索加入书籍。 书籍搜索工作正在进行,但是当作者搜索时,我得到了空白 使用laravel 5.1
id
book_title
book_edition
book_isbn
id
first_name
last_name
auth_address
table books_authors_relationship
book_id
author_id
预订模型
public function author()
{
return $this->belongsToMany('App\Author','books_authors_relationship')->withTimestamps();
}
public function scopeSearchByKeyword($query, $search)
{
if ($search!='') {
$query->where(function ($query) use ($search) {
$query->where("book_title", "LIKE","%$search%")
->orWhere("date_publication", "LIKE", "%$search%")
->orWhere("book_isbn", "LIKE", "%$search%");
});
}
return $query;
}
}
作者模型
public function Book(){
return $this->belongsToMany('App\Book','books_authors_relationship')->withTimestamps();
}
public function scopeSearchByKeyword($query, $search)
{
if ($search!='') {
$query->where(function ($query) use ($search) {
$query->where("first_name", "LIKE","%$search%")
->orWhere("last_name", "LIKE", "%$search%")
->orWhere("auth_address", "LIKE", "%$search%")
->orWhere("auth_DOB", "LIKE", "%$search%");
});
}
return $query;
}
SearchController
public function search_book($id)
{
$search = \Request::get('search');
$sections = Section::find($id);
$authors_list = Book::with('author')->get();
$all_books = Book::SearchByKeyword($search)->withTrashed()->paginate(5);
return view('libraryViewsContainer.admin_book',compact('all_books','sections','authors_list'));
}