php - Laravel searching many to many relationship -
i have many many relation between books table , authors table. pivot table (author_book) contains the author_id , book_id.
i want users able search trough database using simple search form. whenever user enters keyword want search fields in both tables.
what need this...
return view::make('result')->with('books', book::with('authors') ->where('title', 'like', '%'.$keyword.'%') ->orwhere('**authors->table->name**', 'like', '%'.$keyword.'%')->get());
i need way search authors table , check keyword maches author name.
the relation set in both author , book model.
any appreciated
this may not ideal solution complex queries find easier use raw sql queries.
something in case:
$result = db::select(db::raw("select * books inner join authors books.title '%$keyword%' or authors.name '%$keyword%' "));
Comments
Post a Comment