예제 #1
0
 /**
  * Execute the command.
  *
  * @return void
  */
 public function handle()
 {
     $chat = Chat::create($this->data);
     $this->user->chats()->save($chat, ['type' => 'admin']);
     if ($this->project) {
         $this->project->chats()->save($chat);
     }
     event(new FeedableEvent('ChatRoomCreated', $this->user, $chat, null, $this->project, $this->audience));
     return $chat;
 }
예제 #2
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     //Grab all the data we need to instead into the row
     $auth = new Auth();
     $user_id = $auth::user()->id;
     $input = Input::all();
     $param = array("user_id" => $user_id, "message" => $input['message']);
     //Create the row in the database
     $result = Chat::create($param);
     $result['name'] = $auth::user()->name;
     if (is_object($result)) {
         return json_encode($result);
     }
     return false;
 }
예제 #3
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  Request  $request
  * @return Response
  */
 public function store(Request $request)
 {
     //We need to set the Engineer as unavailable
     $e = Engineer::find($request["engineer_id"]);
     $e->available = 0;
     $e->save();
     $post_data = $request->all();
     if ($post_data["engineer_email"]) {
         //Send e-mail to responsible engineer
         $mail = Mail::raw("You have receixed a new chat request, please check the tool now!", function ($message) use($post_data) {
             $message->from('*****@*****.**', 'RTS Tool');
             $message->to($post_data["engineer_email"])->subject('New RTS request!');
         });
     }
     return Chat::create($request->all());
 }
예제 #4
0
 public function addChat(Request $request)
 {
     //Checks if required parameters are provided
     if (!$request->message || !$request->from_user_id || !$request->to_user_id) {
         return Response::json(["status" => "ERROR", "response" => "Message insertion failed"], 400);
     }
     $fromUser = User::where('id', $request->from_user_id)->first();
     $toUser = User::where('id', $request->to_user_id)->first();
     //Checks if from and to user exists
     if (!$fromUser || !$toUser) {
         return Response::json(["status" => "ERROR", "response" => "Message insertion failed"], 400);
     }
     //Insert the message into database
     $chat = Chat::create(array("message" => $request->message, "from_user_id" => $request->from_user_id, "to_user_id" => $request->to_user_id));
     $chat->save();
     //Reply
     return Response::json(["status" => "OK", "response" => $chat], 200);
 }
예제 #5
0
 public function postMsg(Request $request)
 {
     Chat::create($request->input());
 }
예제 #6
0
 public function stestJoinChat()
 {
     $user = User::firstOrFail();
     $chat = Chat::create($this->chatroomdata);
     $action = Bus::dispatch(new JoinChat($user, $chat));
     // add
     $this->assertNull($action->admin);
     $this->assertTrue($chat->users->contains($user->id));
     $this->assertEquals(1, $chat->messages->count());
     $this->assertEquals(1, $chat->users->count());
     $action = Bus::dispatch(new LeaveChat($user, $chat));
     // remove
     $this->assertEquals(2, Message::count());
     //        $this->assertEquals(0, $chat->users->count());
     $admin = User::all()->last();
     $this->assertNotNull($admin);
     $this->assertNotEquals($admin->id, $user->id);
     $action = Bus::dispatch(new JoinChat($user, $chat, $admin));
     // add
     $this->assertEquals($action->admin->id, $admin->id);
     $action = Bus::dispatch(new LeaveChat($user, $chat, $admin));
     // remove
 }