SHARE
TWEET

Untitled

a guest Dec 8th, 2019 84 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.     public function addOffer(AddOffer $request)
  2.     {
  3.         $blocked = 0;
  4.         $visible_for = 'all';
  5.  
  6.         $order = Order::where('id', $request->order_id)->with('offers')->first();
  7.  
  8.         if (Gate::denies('add', [Offer::class, $order])) {
  9.             return redirect()->back();
  10.         }
  11.  
  12.         if (Message::hasInvalidValue($request->message)) {
  13.             $blocked = 1;
  14.             $visible_for = 'executor';
  15.         }
  16.  
  17.         $offer = Offer::create([
  18.             'executor_id' => Auth()->id(),
  19.             'customer_cost' => $request->cost * Auth::user()->x_cost,
  20.             'executor_cost' => $request->cost,
  21.             'order_id' => $request->order_id,
  22.             'blocked' => $blocked,
  23.             'blocked_messages' => $blocked
  24.         ]);
  25.  
  26.         $message = Message::create([
  27.             'offer_id' => $offer->id,
  28.             'message' => $request->message,
  29.             'author_id' => Auth()->id(),
  30.             'is_read' => 'no',
  31.             'visible_for' => $visible_for,
  32.             'blocked' => $blocked
  33.         ]);
  34.  
  35.         OrderHistory::create([
  36.             'order_id' => $request->order_id,
  37.             'user_id' => Auth::user()->id,
  38.             'status' => 'offer_added',
  39.             'customer_cost' => $request->cost * Auth::user()->x_cost,
  40.             'executor_cost' => $request->cost,
  41.             'visible_for' => $visible_for
  42.         ]);
  43.  
  44.         if (!$blocked) {
  45.             broadcast(new OfferChange($offer->id, $message))->toOthers();
  46.             $notification = Notification::create([
  47.                 'type' => 'offer_added',
  48.                 'executor_id' => Auth::id(),
  49.                 'order_id' => $request->order_id,
  50.                 'customer_id' => $order->customer_id,
  51.                 'customer_cost' => $request->cost * Auth::user()->x_cost,
  52.                 'executor_cost' => $request->cost,
  53.                 'visible_for' => 'customer',
  54.                 'message_id' => $message->id
  55.             ]);
  56.  
  57.             broadcast(new NewNotification($order->customer_id, $notification->id))->toOthers();
  58.         } else {
  59.             broadcast(new ValidateMessage($offer->id, $message))->toOthers();
  60.         }
  61.  
  62.         return redirect()->back();
  63.     }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top