original_string: public function postDispatched(Request $request)
      {
          $purchase = Purchase::findOrFail($request->input('purchase_id'));
  
          if ($purchase->item->seller->userId != Auth::user()->userId) {
              return redirect('/inventory/sold')->withErrors(["You are not seller of this item."]);
          }
  
          if ($purchase->isDispatched()) {
              return redirect('/inventory/sold')->withErrors(["This item has already been marked as dispatched."]);
          }
  
          if (!$purchase->deliveryOption) {
              return redirect('/inventory/sold')->withErrors(["This item is due to be collected."]);
          }
  
          $purchase->dispatched = time();
          $purchase->trackingNumber = $request->input('tracking_number');
  
          $purchase->save();
  
          $purchase->buyer->sendEmail(
              'Your item has been dispatched',
              'emails.item.dispatched',
              [
                  'item_name' => $purchase->item->name,
                  'delivery_service' => $purchase->deliveryOption->name,
                  'tracking_number' => $purchase->trackingNumber,
                  'arrival_time' => $purchase->deliveryOption->humanArrivalTime,
              ]
          );
  
          return redirect('/inventory/sold')->withStatus("This item has been marked as dispatched and the buyer notified.");
      }
code: public function postDispatched(Request $request)
      {
          $purchase = Purchase::findOrFail($request->input('purchase_id'));
  
          if ($purchase->item->seller->userId != Auth::user()->userId) {
              return redirect('/inventory/sold')->withErrors(["You are not seller of this item."]);
          }
  
          if ($purchase->isDispatched()) {
              return redirect('/inventory/sold')->withErrors(["This item has already been marked as dispatched."]);
          }
  
          if (!$purchase->deliveryOption) {
              return redirect('/inventory/sold')->withErrors(["This item is due to be collected."]);
          }
  
          $purchase->dispatched = time();
          $purchase->trackingNumber = $request->input('tracking_number');
  
          $purchase->save();
  
          $purchase->buyer->sendEmail(
              'Your item has been dispatched',
              'emails.item.dispatched',
              [
                  'item_name' => $purchase->item->name,
                  'delivery_service' => $purchase->deliveryOption->name,
                  'tracking_number' => $purchase->trackingNumber,
                  'arrival_time' => $purchase->deliveryOption->humanArrivalTime,
              ]
          );
  
          return redirect('/inventory/sold')->withStatus("This item has been marked as dispatched and the buyer notified.");
      }
code_tokens: public function postDispatched ( Request $ request ) { $ purchase = Purchase :: findOrFail ( $ request -> input ( 'purchase_id' ) ) ; if ( $ purchase -> item -> seller -> userId != Auth :: user ( ) -> userId ) { return redirect ( '/inventory/sold' ) -> withErrors ( [ "You are not seller of this item." ] ) ; } if ( $ purchase -> isDispatched ( ) ) { return redirect ( '/inventory/sold' ) -> withErrors ( [ "This item has already been marked as dispatched." ] ) ; } if ( ! $ purchase -> deliveryOption ) { return redirect ( '/inventory/sold' ) -> withErrors ( [ "This item is due to be collected." ] ) ; } $ purchase -> dispatched = time ( ) ; $ purchase -> trackingNumber = $ request -> input ( 'tracking_number' ) ; $ purchase -> save ( ) ; $ purchase -> buyer -> sendEmail ( 'Your item has been dispatched' , 'emails.item.dispatched' , [ 'item_name' => $ purchase -> item -> name , 'delivery_service' => $ purchase -> deliveryOption -> name , 'tracking_number' => $ purchase -> trackingNumber , 'arrival_time' => $ purchase -> deliveryOption -> humanArrivalTime , ] ) ; return redirect ( '/inventory/sold' ) -> withStatus ( "This item has been marked as dispatched and the buyer notified." ) ; }
docstring: Mark a purchase dispatched.
  
  @param \Illuminate\Http\Request $request
  @return \Illuminate\Http\RedirectResponse
docstring_tokens: Mark a purchase dispatched .