Sounds to me that you either have a very poorly written SQL query, or there is an issue with the database, or you have a faulty setup somewhere in your infra structure.
I would suggest installing the Laravel debugbar, or Clockwork to narrow it down a bit, to see where the actual bottle neck is.
I would also like to point out that you have written a shitload of code for something as simple as listing users. I suggest that you in your controller just do.
public function index()
{
return view('users.index')
->with([
'users' => User::orderBy('name')
->paginate(20)
]);
}
If it's still is slow, then it's most likely something with server setup.
I recommend using KISS, rather than the complex pattern you are using.
If you want filtering capabilities you can do something like this.
return view('books.index')
->with([
'books' => BookIndexView::query()
->when($request['authors'], function ($query, $authors) {
$query->whereIn('author_id',
$this->numericStringToArray($authors));
})
->when($request['published'], function ($query, $published) {
$query->where('published_year', $published);
})
->when($request['genre'], function ($query, $genre) {
$query->where('genre', $genre);
})
->when($request['format'], function ($query, $format) {
$query->where('format', $format);
})
->when($request['search'], function ($query, $search) {
$query->where('title', 'LIKE', "%$search%")
->orWhere('author_name', 'LIKE', "%$search%")
->orWhere('series', 'LIKE', "%$search%");
})
->orderBy('author_name')
->orderBy('series')
->orderBy('part')
->orderBy('published_year')
->get(),
]);
```