[dfae77e] | 1 | <?php
|
---|
| 2 |
|
---|
| 3 | namespace App\Http\Controllers;
|
---|
| 4 |
|
---|
| 5 | use App\Models\Artist;
|
---|
| 6 | use App\Models\ArtistType;
|
---|
| 7 | use App\Models\Genre;
|
---|
| 8 | use App\Models\Offer;
|
---|
| 9 | use App\Models\User;
|
---|
| 10 | use Illuminate\Http\Request;
|
---|
| 11 | use Illuminate\Support\Facades\Auth;
|
---|
| 12 | use Illuminate\Support\Facades\DB;
|
---|
| 13 | use PhpParser\Node\Expr\Array_;
|
---|
| 14 |
|
---|
| 15 | class MainController extends Controller
|
---|
| 16 | {
|
---|
| 17 | //
|
---|
| 18 |
|
---|
| 19 | public function __construct()
|
---|
| 20 | {
|
---|
| 21 |
|
---|
| 22 | }
|
---|
| 23 |
|
---|
| 24 | public function index(Request $request)
|
---|
| 25 | {
|
---|
| 26 | $genres = Genre::orderBy('name', 'asc')->get();
|
---|
| 27 | $artist_types = ArtistType::orderBy('name', 'asc')->get();
|
---|
| 28 |
|
---|
| 29 | $artists = Artist::query()
|
---|
| 30 | ->select(
|
---|
| 31 | DB::raw('distinct artists.*')
|
---|
| 32 | )
|
---|
| 33 | ->whereNotNull('admin_verified_at')
|
---|
| 34 | ->join('users', 'users.id', '=', 'artists.user_id')
|
---|
| 35 | ->when(!is_null($request->search_name_criteria), function ($q) use ($request){
|
---|
| 36 | return $q->where('users.name','iLIKE', '%'.$request->search_name_criteria.'%');
|
---|
| 37 | })
|
---|
| 38 | ->when(!is_null($request->artist_type), function ($q) use ($request){
|
---|
| 39 | return $q->whereIn('artist_type_id', $request->artist_type);
|
---|
| 40 | })
|
---|
| 41 | ->when(!is_null($request->music_type) && $request->music_type != 'all', function ($q) use ($request){
|
---|
| 42 | return $q->join('artist_sings_genres','artist_sings_genres.artist_id', '=', 'artists.user_id')
|
---|
| 43 | ->where('artist_sings_genres.genre_id', '=', $request->music_type);
|
---|
| 44 | })
|
---|
| 45 | ->get();
|
---|
| 46 |
|
---|
| 47 | return view('web.main.explore')
|
---|
| 48 | ->with('artists', $artists)
|
---|
| 49 | ->with('genres', $genres)
|
---|
| 50 | ->with('artist_types', $artist_types);
|
---|
| 51 |
|
---|
| 52 | }
|
---|
| 53 | }
|
---|