Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $query = new Posts();
- if (count(Auth::user()->tags) > 0) {
- $query = $query->whereHas('tags', function ($q) {
- $i = 0;
- foreach (Auth::user()->tags as $tag) {
- if ($i == 0) {
- $q->where('title', '=', $tag->title);
- } else {
- $q->orWhere('title', '=', $tag->title);
- }
- $i++;
- }
- });
- }
- $posts = $query->where('isTemplate', true)->orderBy($key, $order)->paginate(15);
- $query = Posts::query()
- ->where('isTemplate', true)
- ->orderBy($key, $order);
- if (Auth::user()->tags->isNotEmpty()) {
- $tags = Auth::user()
- ->tags
- ->pluck('title')
- ->toArray();
- $query = $query->whereIn('tags', $tags);
- }
- $posts = $query->paginate(15);
Add Comment
Please, Sign In to add comment