source: app/Http/Controllers/ReviewController.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: 1.6 KB
Line 
1<?php
2
3namespace App\Http\Controllers;
4
5use App\Enum\OfferStatus;
6use App\Models\Artist;
7use App\Models\Offer;
8use App\Models\Organizer;
9use App\Models\Review;
10use Illuminate\Http\Request;
11use Illuminate\Support\Facades\Auth;
12
13class ReviewController extends Controller
14{
15 //
16 public function __construct()
17 {
18 $this->middleware(['auth', 'verified', 'onboarding', 'role:organizer']);
19 }
20
21 /**
22 * Store a newly created resource in storage.
23 *
24 * @return \Illuminate\Http\RedirectResponse
25 */
26 public function store(Request $request)
27 {
28 $hasFinishedOfferForTheArtist = Offer::join('events', 'events.id', '=', 'offers.event_id')
29 ->join('organizers', 'organizers.user_id', '=', 'events.organizer_id')
30 ->where('organizers.user_id', '=', Auth::id())
31 ->where('offers.artist_id', '=', $request->artist_id)
32 ->where('offers.status', '=', OfferStatus::COMPLETED->value)
33 ->exists();
34
35 if ($hasFinishedOfferForTheArtist) {
36 $review = new Review();
37 $review->content = $request->comment;
38 $review->rating = $request->rating;
39
40 $organizer = Organizer::find(Auth::id());
41 $review->organizer()->associate($organizer);
42
43 $artist = Artist::find($request->artist_id);
44 $review->artist()->associate($artist);
45
46 $review->save();
47
48 return redirect()->back();
49 } else {
50 return redirect()->back()
51 ->with('warning', 'You can not post a review for this artist!');
52 }
53 }
54}
Note: See TracBrowser for help on using the repository browser.