get(); $artist_types = ArtistType::orderBy('name', 'asc')->get(); $artists = Artist::query() ->select( DB::raw('distinct artists.*') ) ->whereNotNull('admin_verified_at') ->join('users', 'users.id', '=', 'artists.user_id') ->when(!is_null($request->search_name_criteria), function ($q) use ($request){ return $q->where('users.name','iLIKE', '%'.$request->search_name_criteria.'%'); }) ->when(!is_null($request->artist_type), function ($q) use ($request){ return $q->whereIn('artist_type_id', $request->artist_type); }) ->when(!is_null($request->music_type) && $request->music_type != 'all', function ($q) use ($request){ return $q->join('artist_sings_genres','artist_sings_genres.artist_id', '=', 'artists.user_id') ->where('artist_sings_genres.genre_id', '=', $request->music_type); }) ->get(); return view('web.main.explore') ->with('artists', $artists) ->with('genres', $genres) ->with('artist_types', $artist_types); } }