Answer the question
In order to leave comments, you need to log in
Is it possible to optimize this query to the database?
There is a directory of sites (sites are checked before being added to the directory, that is, with the status `rejected = 0` and `accepted = 1`), the sites have tags. So I want to display all tags with relationships with sites with the status `accepted` (randomly 50 pcs.).
For tagging, I use the `cartalyst/tags: v2.1` package, and for convenience, I created a `Tag` model and set up relationships (since the package itself does not provide a model for working with tags directly)...
The request itself looks like this:
$tags = Tag::whereHas('catalogue', function ($query) {
$query->where('status', 1);
})
->orderBy(DB::raw('RAND()'))
->take(50)
->get();
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question