Exemple #1
0
 public function scopeStatus($query, $status)
 {
     $state_id = OrderState::where('name', $status)->pluck('id');
     return $query->where('state_id', $state_id);
 }
 /**
  * Call: PUT (/orders/{orders}/deactivate)
  *
  * Deactivate an order. This will serve for: declining an order (before it's been processed) and cancelling it (after it's been processed)
  * In bothe cases, we call delete() method on a model, which soft-deletes a record (sets the deleted_at timestamp). So if an employee does
  * one of above mentioned actions, you should call this function.
  * @param $id
  */
 public function deactivate($id)
 {
     $order = Order::find($id);
     $state = $order->state()->first();
     if ($state->name == 'pending') {
         $order->state_id = OrderState::where('name', 'declined')->first()->id;
         $order->acquired_by = auth()->user()->userable_id;
         $order->save();
         $order->delete();
         return redirect('/')->with('message', 'Uspešen preklic naročila.');
     } else {
         $order->state_id = OrderState::where('name', 'cancelled')->first()->id;
         $order->save();
         $order->delete();
         return redirect('/')->with('message', 'Uspešen storno naročila.');
     }
 }