source: app/Http/Controllers/ArtistController.php

Last change on this file was dfae77e, checked in by Igor Danilovski <igor_danilovski@…>, 2 years ago
  • Initial commit;
  • Property mode set to 100644
File size: 3.2 KB
RevLine 
[dfae77e]1<?php
2
3namespace App\Http\Controllers;
4
5use App\Enum\OfferStatus;
6use App\Enum\UserType;
7use App\Models\Artist;
8use App\Models\Event;
9use App\Models\Offer;
10use App\Models\Organizer;
11use App\Models\User;
12use Illuminate\Http\Request;
13use Illuminate\Support\Facades\Auth;
14
15class ArtistController extends Controller
16{
17 //
18 public function __construct()
19 {
20 $this->middleware(['auth', 'verified', 'onboarding', 'role:artist'])->except('show');
21 }
22
23 /**
24 * Display the specified resource.
25 *
26 * @param int $id
27 * @return \Illuminate\Contracts\Foundation\Application|\Illuminate\Contracts\View\Factory|\Illuminate\Contracts\View\View
28 */
29 public function show($username)
30 {
31 $user = User::where('username', $username)->firstOrFail();
32 $artistProfile = Artist::with('user')
33 ->whereHas('user', function ($query) use ($username) {
34 return $query->where('username', '=', $username);
35 })->firstOrFail();
36
37 if (!Auth::guest()) {
38 switch (Auth::user()->type) {
39 case UserType::ORGANIZER->value:
40 $hasFinishedOfferForTheArtist = Offer::join('events', 'events.id', '=', 'offers.event_id')
41 ->join('organizers', 'organizers.user_id', '=', 'events.organizer_id')
42 ->join('artists', 'artists.user_id', '=', 'offers.artist_id')
43 ->where('organizers.user_id', '=', Auth::id())
44 ->where('artists.user_id', '=', $user->id)
45 ->where('offers.status', '=', OfferStatus::COMPLETED->value)
46 ->exists();
47 break;
48 case UserType::MANAGER->value:
49 $abilityToSeeAndManageOffers = $artistProfile->manager_id === Auth::id();
50
51 $abilityToSeeAndManageOffers ?
52 $offers = Offer::select('offers.*')
53 ->join('events', 'events.id', '=', 'offers.event_id')
54 ->where('artist_id', $artistProfile->user_id)
55 ->orderBy('offers.status', 'asc')
56 ->orderBy('events.event_date', 'desc')
57 ->paginate(15) : $offers = null;
58 break;
59 }
60 }
61
62 return view('web.artist.profile')
63 ->with('artist', $artistProfile)
64 ->with('abilityToPostReview', $hasFinishedOfferForTheArtist ?? false)
65 ->with('abilityToSeeAndManageOffers', $abilityToSeeAndManageOffers ?? false)
66 ->with('offers', $offers ?? null);
67 }
68
69 public function showManager()
70 {
71 $artist = Artist::with('user')
72 ->where('user_id', Auth::id())
73 ->firstOrFail();
74
75 return view('web.artist.manager.manager')
76 ->with('artist', $artist);
77 }
78
79 public function removeManager()
80 {
81 $artist = Artist::with('user')
82 ->where('user_id', Auth::id())
83 ->firstOrFail();
84
85 $artist->manager_id = null;
86
87 try {
88 $artist->update();
89 } catch (Exception $e) {
90 return redirect()->back()
91 ->with('error', $e->getMessage());
92 }
93
94 return redirect()
95 ->back();
96 }
97}
Note: See TracBrowser for help on using the repository browser.