Currently I am searching for posts by either title, posts containing a tag, or posts made by a user.
$term = Input::get('q');
$posts = Post::whereHas('tags', function($query) use($term) {
$query->where('name', 'LIKE', '%'.$term.'%');
})->orWhere('title','LIKE','%'.$term.'%')
->orWhere('username', 'LIKE', '%'.$term.'%')->paginate(24);
I have two tables - Posts and Images, in table Posts I store an image and text, and in table Images I store only an image. I also have two pivot tables post_tag and image_tag.
My question is - can I somehow, when searching for posts that contain tag, to search for records from table images tagged with the same tag and display the result?
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire