samedi 27 mai 2017

Searching from two tables by tags Eloquent

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?



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2rs92Mq
via IFTTT

Aucun commentaire:

Enregistrer un commentaire