public static function sendMessage($typeName, $senderId, $receiverId, $title, $content, $sendTime = null, $status = 1) { $message = new Message(); $message->typeId = MessageType::find("name", $typeName)->first()->id; $message->senderId = $senderId; $message->receiverId = $receiverId; $message->title = $title; $message->content = $content; $message->sendTime = $sendTime; $message->status = $status; if (!isset($message->sendTime) || $message->sendTime == '') { $message->sendTime = date('Y-m-d H:i:s'); } $message->save(); return $message; }
public function postDelMsgType() { $id = Input::get('id'); $validator = Validator::make(array('id' => $id), $this->validate_id_arr); if ($validator->fails()) { return json_encode(array(false, "Invalid notification type ID")); // return Redirect::to('message-types') // ->with('msg', 'Invalid notification type ID') // ->with('state', '-1'); } $type_id = $id; // $checkUsed = $this->checkMsgTypeUsed($type_id); // if ($checkUsed) { // return "Can't delete Notification Type.It's used"; // } $type = MessageType::find($type_id); if (!$type) { return json_encode(array(false, "Type isn't found")); } try { MessageTypeColums::where('type_id', '=', $type_id)->delete(); $type->delete(); return json_encode(array(true, "Notification type deleted successfully")); // return Redirect::to('message-types') // ->with('msg', 'Notification type deleted successfully'); } catch (Exception $e) { return json_encode(array(false, "Can\\'t delete notification type")); // return Redirect::to('message-types') // ->with('msg', 'Can\'t delete notification type') // ->with('state', '-1'); } }