Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public function addOffer(AddOffer $request)
- {
- $blocked = 0;
- $visible_for = 'all';
- $order = Order::where('id', $request->order_id)->with('offers')->first();
- if (Gate::denies('add', [Offer::class, $order])) {
- return redirect()->back();
- }
- if (Message::hasInvalidValue($request->message)) {
- $blocked = 1;
- $visible_for = 'executor';
- }
- $offer = Offer::create([
- 'executor_id' => Auth()->id(),
- 'customer_cost' => $request->cost * Auth::user()->x_cost,
- 'executor_cost' => $request->cost,
- 'order_id' => $request->order_id,
- 'blocked' => $blocked,
- 'blocked_messages' => $blocked
- ]);
- $message = Message::create([
- 'offer_id' => $offer->id,
- 'message' => $request->message,
- 'author_id' => Auth()->id(),
- 'is_read' => 'no',
- 'visible_for' => $visible_for,
- 'blocked' => $blocked
- ]);
- OrderHistory::create([
- 'order_id' => $request->order_id,
- 'user_id' => Auth::user()->id,
- 'status' => 'offer_added',
- 'customer_cost' => $request->cost * Auth::user()->x_cost,
- 'executor_cost' => $request->cost,
- 'visible_for' => $visible_for
- ]);
- if (!$blocked) {
- broadcast(new OfferChange($offer->id, $message))->toOthers();
- $notification = Notification::create([
- 'type' => 'offer_added',
- 'executor_id' => Auth::id(),
- 'order_id' => $request->order_id,
- 'customer_id' => $order->customer_id,
- 'customer_cost' => $request->cost * Auth::user()->x_cost,
- 'executor_cost' => $request->cost,
- 'visible_for' => 'customer',
- 'message_id' => $message->id
- ]);
- broadcast(new NewNotification($order->customer_id, $notification->id))->toOthers();
- } else {
- broadcast(new ValidateMessage($offer->id, $message))->toOthers();
- }
- return redirect()->back();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement