source: app/Http/Controllers/MainController.php@ dfae77e

Last change on this file since dfae77e was dfae77e, checked in by Igor Danilovski <igor_danilovski@…>, 2 years ago
  • Initial commit;
  • Property mode set to 100644
File size: 1.7 KB
Line 
1<?php
2
3namespace App\Http\Controllers;
4
5use App\Models\Artist;
6use App\Models\ArtistType;
7use App\Models\Genre;
8use App\Models\Offer;
9use App\Models\User;
10use Illuminate\Http\Request;
11use Illuminate\Support\Facades\Auth;
12use Illuminate\Support\Facades\DB;
13use PhpParser\Node\Expr\Array_;
14
15class 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}
Note: See TracBrowser for help on using the repository browser.