Example #1
0
 public static function destroy($outlets, $id = null)
 {
     $serviceIds = $dealIds = $outletIds = [];
     if (!empty($outlets)) {
         if ($id) {
             array_push($outletIds, $id);
         } else {
             foreach ($outlets as $key => $outlet) {
                 array_push($outletIds, $outlet->id);
             }
         }
         $services = Service::whereIn('outlet_id', $outletIds)->get();
         foreach ($services as $key => $service) {
             array_push($serviceIds, $service->id);
         }
         // delete deal
         $deals = Deal::whereIn('service_id', $serviceIds)->get();
         foreach ($deals as $key => $deal) {
             array_push($dealIds, $deal->id);
         }
         // delete deal transaction
         DealTransaction::whereIn('deal_id', $dealIds)->delete();
         Deal::whereIn('id', $dealIds)->delete();
         Service::whereIn('id', $serviceIds)->delete();
         Outlet::whereIn('id', $outletIds)->delete();
     }
 }
 /**
  * Remove the specified outlet from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroyService($service)
 {
     $deals = Deal::where('service_id', $service->id)->get();
     if (!empty($deals)) {
         $dealIds = [];
         foreach ($deals as $key => $deal) {
             array_push($dealIds, $deal->id);
         }
         DealTransaction::whereIn('deal_id', $dealIds)->delete();
         Deal::whereIn('id', $dealIds)->delete();
     }
     $service->delete();
     return Redirect::to('admin/services');
 }