public function testRuleCamposRequeridosSatisfeitos() { $model = new Message(); $this->assertFalse($model->validate()); $model->author_email = '*****@*****.**'; $model->author_name = 'test'; $model->message = str_repeat('A', 140); $this->assertTrue($model->validate()); }
public function actionView($id) { $message = Message::findOne($id); $messages = Message::find()->where(['number' => $message->number])->all(); $model = Project::findOne($message->project_id); $reply = new Message(); foreach ($messages as $item) { $item->status = 4; $item->save(); } if ($reply->load(Yii::$app->request->post()) && $reply->validate()) { // $reply->user_id = $reply->project_id = $message->project_id; $reply->status = 1; $reply->time = time(); $reply->type = 'text'; $reply->save(); // Send twilio Text through project model $model->sendText([$message->user_id], $reply->message); Yii::$app->session->setFlash('success', 'Message Sent'); $this->redirect(['/project/messages', 'id' => $message->project_id]); } return $this->render('view', ['message' => $message, 'messages' => $messages, 'model' => $model, 'reply' => $reply]); }
/** * Store a newly created resource in storage. * POST /messages * * @return Response */ public function store() { $data = Input::all(); if (!Auth::check() && isset($data['email'])) { $result = $this->registerUser($data, Config::get('constants.ROLE_BROKER')); Log::info($result); if (is_array($result)) { return View::make('users.fastcomposer')->withErrors($result); } } if (Auth::check()) { $data['sender_id'] = Auth::user()->id; $msg = new Message(); if ($msg->validate($data)) { $msg->fill($data); $msg->last_reply = Carbon::now()->toDateTimeString(); $msg->save(); if (Request::ajax()) { return Response::json($msg); } return Redirect::intended("inbox/{$msg->id}"); } if (Request::ajax()) { return Response::json($msg->getValidator, 400); } return View::make(Auth::user()->role->name . '.messages.create')->withErrors($msg->getValidator()); } }