public function run() { DB::table('notification_types')->truncate(); EloquentNotificationTypeRepository::create(["name" => "Email Notification", "type" => "email"]); EloquentNotificationTypeRepository::create(["name" => "Product Inventory Notification", "type" => "inventory"]); EloquentNotificationTypeRepository::create(["name" => "Thumbs Notification", "type" => "thumbs"]); EloquentNotificationTypeRepository::create(["name" => "Sales Notification", "type" => "sales"]); EloquentNotificationTypeRepository::create(["name" => "Billing Notification", "type" => "billing"]); EloquentNotificationTypeRepository::create(["name" => "Subscription Notification", "type" => "subscription"]); }
/** * @param $driver * * @return \Illuminate\Http\JsonResponse */ public function destroy($driver = NULL) { try { \DB::beginTransaction(); if (is_null($driver)) { $driver = $this->getAuthenticatedDriver(); } if ($notifications = $driver->notifications) { $notifications->map(function ($notification) { if (EloquentNotificationTypeRepository::find($notification->type_id)->type == 'sales') { if (Payment::find($notification->value)->status == 0) { return; } } $notification->delete(); }); \DB::commit(); return $this->setStatusCode(204)->respond(['success' => true, 'message' => $this->translator->trans('notifications.deleted')]); } return $this->setStatusCode(404)->respondWithError($this->translator->trans('notifications.no_available_resources')); } catch (\Exception $e) { return $this->errorInternalError(); } }
/** * Set type value. */ public function setTypeAttribute() { $this->attributes['type_id'] = EloquentNotificationTypeRepository::findByType($this->type)->id; }
/** * Get driver notifications with conditions * * @param $from * * @param $to * * @return mixed */ public function with_notifications($from, $to) { $query = $this->notifications(); if (!$this->notify_sale) { $query->where('type_id', '<>', EloquentNotificationTypeRepository::findByType('sales')->id); } if (!$this->notify_inventory) { $query->where('type_id', '<>', EloquentNotificationTypeRepository::findByType('inventory')->id); } if (!$this->notify_feedback) { $query->where('type_id', '<>', EloquentNotificationTypeRepository::findByType('thumbs')->id); } if (!$this->notify_others) { $query->where('type_id', '<>', EloquentNotificationTypeRepository::findByType('emails')->id); } return $query->where('created_at', '>=', $from)->where('created_at', '<=', $to)->orderBy('created_at', 'desc')->get(); }