My search and tags not working because of my structure

Posted 3 years ago by raygun

My search not working because of my structure

my tags work like this

public function index(Request $request)
    {
        $tag = $request->get('tag');
        $data = $this->dispatch(new BlogIndexData($tag));
        $layout = $tag ? Tag::layout($tag) : 'blog.layouts.index';

        return view($layout, $data);
    }

but when I try to add search functionality like this

public function index(Request $request)
    {
        $query = $request->get('q');
        $posts = $query
            ? Post::search('%'.$query.'%', ['title', 'subtitle', 'content_raw', 'tags.title'])->paginate(15)
            : Post::orderBy('published_at', 'desc')->paginate(15);
        $videos = $query
            ? Video::search('%'.$query.'%', ['title', 'subtitle', 'content_raw'])->paginate(15)
            : Video::orderBy('published_at', 'desc')->paginate(15);
    
        $tag = $request->get('tag');
        $data = $this->dispatch(new BlogIndexData($tag));
        $layout = $tag ? Tag::layout($tag) : 'blog.layouts.index';

        return view($layout, $data)->withPosts($posts)->withVideos($videos);
    }

the tags don't work BUT the search does work. any suggestions?

Please sign in or create an account to participate in this conversation.