Example #1
0
 /**
  * @param GammaSelection $gamma
  * @param ProductSelection $products
  * @param GammaNotification $notifications
  */
 public function handle(GammaSelection $gamma, ProductSelection $products, GammaNotification $notifications)
 {
     if ($this->shouldNotRun($products, $notifications)) {
         return;
     }
     $selections = $products->newQueryWithoutScopes()->join('product_gamma_categories', 'product_gamma_categories.selection_id', '=', 'product_gamma.id')->where('account_id', $this->account->id)->where('brand_id', $this->brand->id)->where('category_id', $this->category->id)->get(['product_gamma.*']);
     foreach ($selections as $selection) {
         $selections->load(['categories' => function ($query) {
             $query->withTrashed();
         }]);
         foreach ($selection->categories as $category) {
             $category->forceDelete();
         }
         $selection->forceDelete();
     }
     $selections = $gamma->newQueryWithoutScopes()->where(['account_id' => $this->account->id, 'brand_id' => $this->brand->id, 'category_id' => $this->category->id])->get();
     foreach ($selections as $selection) {
         $selection->delete();
     }
 }