we have a books table, and When I click on Harry Potter Part 1, it will show me the other parts below, such as Harry Potter Part 2 or Part 3, I try like query
or group by
I tried these but to no result
public function book(Request $request)
{
$book = books::find($request->id);
return [
'book' => $book,
'more_books' => books::
->whereNotIn('id', [$book->id])
->where('title', 'like', '%' . $book->title. '%')
->get()
];
}
output :
{
"book": {
"id": 40,
"price": 20,
"title": "Harry Potter Part 1"
},
"more_books": []
}
2
Answers
if this is mysql you would use the MATCH() function to return a relevance, and play around with the results you get from this (and add fullext index to the table). I think in laravel you’ll need to add a whereraw in the query builder. Look up the Match function. Other dbs will have the same or similar.